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

Why won't my hat script work?

Asked by 8 years ago

So this script I made is supposed to give the player a hat once they click on an imagebutton (the script is inside the imagebutton) But when they click it, they don't get the hat. Would anyone be kind enough to show me what I did wrong?

local replicatedstorage = game:GetService("ReplicatedStorage") 
local hat = replicatedstorage:WaitForChild("SkullMask") 


script.Parent.MouseButton1Down:connect(function() 
        wait(1) 
        if(char and plr and char:FindFirstChild("Humanoid")) then 
            for i, v in pairs(char:GetChildren()) do 
                if(v) then 
                    if(v:IsA("Hat")) then 
                        v:Destroy() 
                    end 
                end 
            end 
            local clone = hat:Clone() 
            clone.Parent = char      
        end  
    end) 
end)

Thanks guys!

1 answer

Log in to vote
1
Answered by
Merely 2122 Moderation Voter Community Moderator
8 years ago

You never defined the variables char and plr.

local plr = game.Players.LocalPlayer
local char = plr.Character
0
Thanks a lot! This really helped. kelimeguy 60 — 8y
Ad

Answer this question