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

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

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

0

post full script.

0

and maybe try if Player.Character.Humanoid:GetState == 4 then instead?

0

That doesn't work. When comparing enumerations, you must use enumerations. And @OP, it is if Player.Character.Humanoid:GetState() == Enum.HumanoidStateType.Swimming

0

Thank you! That worked!

1 answer

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)

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