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

keep having an error with getting the playerscript even if with a WaitForChild?

Asked by 2 years ago

I have a part with click detector thats when clicked, it goes up to the player the playerscripts and finally setting the value of disable to false, when I did it on the first try it gave me an error so i put :WaitForChild() for the player scripts, but its giving me this error Infinite yield possible on 'Players.ninjanerd601:WaitForChild("PlayerScripts")

the script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local remoteEvent = ReplicatedStorage:WaitForChild("PickupItem")
local click = script.Parent.ClickDetector

local text = script.Parent.MouseoverText.Value

click.MouseClick:Connect(function(click)
    click:WaitForChild("PlayerScripts").Flashlight.Disabled = false --I have a :WaitForChild in this part
    script.Parent.Sound:Play()
    remoteEvent:FireAllClients(text)
    wait(0.235)
    script.Parent:Destroy()
end)

please help, ty

1 answer

Log in to vote
1
Answered by 2 years ago

I think this is because the click:WaitForChild("PlayerScripts") at line 09 is referring to the click variable at line 04, so when you are trying to :WaitForChild("PlayerScripts"), it will wait for it the whole time and since the ClickDetector has no child with the name of PlayerScripts it will keep waiting.

-- Changed to player instead of click
click.MouseClick:Connect(function(player) 

    -- Also changed to player here
    player:WaitForChild("PlayerScripts").Flashlight.Disabled = false 
    script.Parent.Sound:Play()
Ad

Answer this question