Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Hat Script| Not working? [Unsolved] EDITED

Asked by 8 years ago

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

Log in to vote
0
Answered by 8 years ago

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)
0
Still not working... pluginfactory 463 — 8y
0
Let me re-create the whole thing to see what's wrong. I'll get back to you as soon as I can User#6200 10 — 8y
Ad

Answer this question