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

[Answered] Code is not executing when player torso is at specific location?

The title might be confusing, but I'm trying to make it so that if the players Y axis is below 466, then a drinking code executes. The problem is that it doesn't detect where the players Y axis is at... It just executes early.

Here's the script.

game.Players.PlayerAdded:connect(function(ply)
	ply.CharacterAdded:connect(function(char)
		char:WaitForChild("Torso")
		local torso = char.Torso
		torso.Changed:connect(function()
			if torso.Position.Y <= 466.943 then
				print("Player is at drinking distance")
			end
		end)
	end)
end)

The post has been answered now. Although it is Redbullusa who answered my question, I would like to thank Goulstem too.

3 comments

0

Well because Position.y is wrong.

0

Even so, it does not work.

1

Don't use the "Changed" event on Position properties. Rather, use a "while" loop to check if the player's torso is on/below the intended intercept.

1 answer

✓ Accepted answer

The Y member of a Vector is case senstitive! You need to have Y rather than y.

game.Players.PlayerAdded:connect(function(ply)
	ply.CharacterAdded:connect(function(char)
		char:WaitForChild("Torso")
		local torso = char.Torso
		torso.Changed:connect(function()
			if torso.Position.Y <= 466.943 then
				print("Player is at drinking distance")
			end
		end)
	end)
end)

2 comments

0

Like I said, even if I have it capitalized, the script executes early and does nothing when at the targeted position.

0

Well you are telling it to print, have you tried reading the output?

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