I am creating a character creator and I am trying to add hair. To add the hair I need to add a system that moves the hair to backpack if they pick something else. Here is bits of code of the system but when I click on the button, a hat spawns, but they keep spawning on top of each other which I don't want. I tried this system but it doesn't work, how would you fix this code?
hairs = {}
for h = 1,6 do
hairs[h] = game.ServerStorage.Hair["Hair"..h]:Clone()
hairs[h].Parent = Player.Backpack
end
Whatisin = {}
function HairUpdate()
if H_Val == 0 then
wait(.01)
else
hairs[H_Val].Parent = Character
table.insert(Whatisin, 1, hairs[H_Val])
end
end
function HFrontUpdateVal ()
if #table == 0 then
H_Val = (H_Val + 1) % 6
else
Whatisin[1].Parent = Player.Backpack
table.remove(Whatisin, 1)
H_Val = (H_Val + 1) % 6
end
end
function HBackUpdateVal ()
if #table == 0 then
if H_Val == 0 then
H_Val = 5
else
H_Val = H_Val - 1
end
else
Whatisin[1].Parent = Player.Backpack
table.remove(Whatisin, 1)
if H_Val == 0 then
H_Val = 5
else
H_Val = H_Val - 1
end
end
end |