Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Hat Script| Not working? [Unsolved] EDITED

There are no errors. The goal is to change a hat based on several variables.

plr = game.Players.LocalPlayer
char = plr.Character
plrstats = script.Parent.Parent.PlayerStats
hatval = plrstats.ActiveHat

function onChanged(property)
    if property == hatval then
if hatval.Value == "TempleSoldier1" then
    game.ReplicatedStorage.Hats.TempleSoldier1:clone().Parent = char
elseif hatval.Value == "TempleSoldier2" then
   game.ReplicatedStorage.Hats.TempleSoldier2:clone().Parent = char
elseif hatval.Value == "TempleSoldier3" then
    game.ReplicatedStorage.Hats.TempleSoldier3:clone().Parent = char
        end
    end
end
plr.Changed:connect(onChanged)

THANKS

1 answer

✓ Accepted answer

Firstly, in line 08 you put "hatval" in "", instead of leaving it as hatval. Secondly, there are only 2 'end's, when there should be 3. Here is the corrected script, it should work now;

plr = game.Players.LocalPlayer
char = plr.Character
plrstats = script.Parent.Parent.PlayerStats
hats = script.Parent.Parent.Hats
hatval = plrstats.ActiveHat
 
function onChanged(property)
    if property == hatval then
if plr ~= nil and hatval.Value == "TempleSoldier1" then
    H = hats:findFirstChild(hatval.Value)
    H.Parent = char
    H.Position = char.Head.Position
elseif plr ~= nil and hatval.Value == "TempleSoldier2" then
    H = hats:findFirstChild(hatval.Value)
    H.Parent = char
    H.Position = char.Head.Position
elseif plr ~= nil and hatval.Value == "TempleSoldier3" then
    H = hats:findFirstChild(hatval.Value)
    H.Parent = char
    H.Position = char.Head.Position
		end
	end
end
plr.Changed:connect(onChanged)

2 comments

0

Still not working...

0

Let me re-create the whole thing to see what's wrong. I'll get back to you as soon as I can

This discussion is preserved as it was. New answers, comments, and votes are closed.