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

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

Asked by 6 years ago
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

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`. TheeDeathCaster 2368 — 6y
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)` TheeDeathCaster 2368 — 6y

1 answer

Log in to vote
0
Answered by
lukeb50 631 Moderation Voter
6 years ago
Edited 6 years ago

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

Ad

Answer this question