So I have this script that should fire a remote event if the player does not have an item in the character, but it does not fire and gives the error of the player. of course not having it, any help?
> local Player = game.Players.LocalPlayer
>
> script.Parent.Activated:connect(function()
>
> if Player.Character.MaskForHide == false then
>
> script.Parent.GiveMask:FireServer()
>
> else
>
> if Player.Character:WaitForChild("MaskForHide") then
>
> script.Parent.RemoveMask:FireServer()
>
> end
>
> end
>
> end)
Huh? No it won’t. WaitForChild will infinitely yield until the object is found if you don’t specify a timeout value or return nil if you specify a timeout value and the timeout is reached before finding an object.
Problem is:
MaskForHide is not a valid member of Model and there’s no object that allows you to shorthand like this. What you should be doing here is determining if a hat exists.
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
script.Parent.Activated:Connect(function ()
if Character then
local hasMask = Character:FindFirstChild("MaskForHide")
if hasMask then
script.Parent.RemoveMask:FireServer()
else
script.Parent.GiveMask:FireServer()
end
end
end)
A note on the above: you could just use one remote and pass a boolean to determine whether it should be removed or not, instead of creating two separate remotes.
script.Parent.MaskEquip:Fire(hasMask)
-- On server: if hasMask, destroy, otherwise give