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

How would I be able to detect if a player is in the Swimming StateType?

Asked by 5 years ago

I am trying to create a function that doesn't allow the player to perform something if they are swimming in terrain water.

function build ()
    if Player.Character.Humanoid:GetState(Enum.HumanoidStateType.Swimming) then
        print "you're not allowed to build that here!"
    else
        print "you can build here"
    end
end

script.Parent.MouseButton1Click:Connect(build)

The problem is, this make it so "you're not allowed to build that here!" is printed even when the player is not swimming. It always prints that no matter what state the player is in.

How could I make this function work so it only prints if the player is swimming?

0
post full script. radusavin366 617 — 5y
0
and maybe try if Player.Character.Humanoid:GetState == 4 then instead? radusavin366 617 — 5y
0
That doesn't work. When comparing enumerations, you must use enumerations. And @OP, it is if Player.Character.Humanoid:GetState() == Enum.HumanoidStateType.Swimming User#19524 175 — 5y
0
Thank you! That worked! ShinyGriffin 129 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

Thank you @incapaz, this solution worked.

function build ()
    if Player.Character.Humanoid:GetState() == Enum.HumanoidStateType.Swimming then
        print "you're not allowed to build that here!"
    else
        print "you can build here"
    end
end
script.Parent.MouseButton1Click:Connect(build)
Ad

Answer this question