I'm trying to make a script that will equipped a mask to the player every time that the value is true, and that the mask's mesh id can be changed via a shop, so here's the code for the mask giver
while true do
if game.workspace.ActiveGame == true then
function onTouched(hit)
if hit.Parent:FindFirstChild("AnonHat") == nil then
local c = hit.Parent:GetChildren()
for i=1,#c do
if c[i].className == "Hat" then
c[i]:remove()
end
end
h = Instance.new("Hat")
p = Instance.new("Part")
h.Name = "AnonHat"
p.Parent = h
p.Position = hit.Parent:findFirstChild("Head").Position
p.Name = "Handle"
p.formFactor = 0
p.Size = Vector3.new(1,1,1)
p.BottomSurface = 0
p.TopSurface = 0
p.Locked = true
z = game.workspace.mask
x = z:clone().Parent == p
p.Mesh.Script.Disabled = false
h.Parent = hit.Parent
h.AttachmentPos = Vector3.new(0, 0.5, 0.6)
end
end
function onPlayerRespawn(property, player)
wait()
if property == "Character" and player.Character ~= nil then
local head = player.Character:FindFirstChild("Head")
while head == nil do
wait(0.1)
head = player.Character:FindFirstChild("Head")
end
onTouched(head)
end
end
function onPlayerEntered(newPlayer)
while true do
if newPlayer.Character ~= nil then break end
wait(1)
end
onPlayerRespawn("Character", newPlayer)
newPlayer.Changed:connect(function(property) onPlayerRespawn(property, newPlayer) end )
end
game.Players.ChildAdded:connect(onPlayerEntered)
local c = game.Players:GetChildren()
for i=1,#c do
onPlayerEntered(c[i])
end
end

4 comments
im not good at lua so i cant help with it very much but i did notice on line 15 you forgot to capitalize Find in FindFirstChild :)
doesnt need to be
like i said im a noob :p only thing my noob eyes could notice hehe
i don't understand the reason for the while loop at the start