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

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

Asked by 9 years ago

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.

0
Well because Position.y is wrong. iNicklas 215 — 9y
0
Even so, it does not work. InfraredChasm 35 — 9y
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. Redbullusa 1580 — 9y

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

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)
0
Like I said, even if I have it capitalized, the script executes early and does nothing when at the targeted position. InfraredChasm 35 — 9y
0
Well you are telling it to print, have you tried reading the output? iNicklas 215 — 9y
Ad

Answer this question