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?

4 comments
post full script.
and maybe try if Player.Character.Humanoid:GetState == 4 then instead?
That doesn't work. When comparing enumerations, you must use enumerations. And @OP, it is if Player.Character.Humanoid:GetState() == Enum.HumanoidStateType.Swimming
Thank you! That worked!