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

Why won't my hat script work?

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

✓ Accepted answer

You never defined the variables char and plr.

local plr = game.Players.LocalPlayer
local char = plr.Character

1 comment

0

Thanks a lot! This really helped.

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