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

Why is it saying Infinite Yield Possible and why isn't the script working?

part_position = 40.9, 8.35, -1.8
player = game.Players.LocalPlayer
game.Players:WaitForChild('LocalPlayer')
player:WaitForChild('Character')
if player.Character and (player.Character.Torso.Position-part_position).magnitude < 5 then
script.Parent.CanCollide = false
wait(5)
script.Parent.CanCollide = true
end

Idk where I went wrong

3 comments

1

The WaitForChild function waits for an object. The Player may be and object, but in a localscript, you wont get the client that way: You have to do it Players.LocalPlayer. Same with the player's character Players.LocalPlayer.Character.

1

Another thing to note is that you set up part_position to be a Vector3, but you didn't translate the values into a vector. Just simply add the values into a Vector3 value. Vector3(x,y,z)

1 answer

That message means that WaitForChild cannot find the object you requested after a short ammount of time.

Your problem is that localplayer is a property of Players, not an object within it. Fixed Code:

part_position = 40.9, 8.35, -1.8
player = game.Players.LocalPlayer
player.CharacterAdded:wait()--how to wait for the character
if player.Character and (player.Character.Torso.Position-Vector3.new(part_position)).magnitude < 5 then
script.Parent.CanCollide = false
wait(5)
script.Parent.CanCollide = true
end

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