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

How do I make this Humanoid:ChangeState script work?

So, been working on this little thing where I want the player to climb up the wall using Humanoid:ChangeState, but it's not erroring in the DEV CONSOLE and also Iv'e tried adding a print function so I can troubleshoot but it also doesnt print inside of the function, here is the code I really need this to work thanks in advance!

local plr = game:GetService("Players")
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")

script.Parent.Touched:Connect(function(hit)
        if hit.Parent == hum then
        hum.ChangeState(Enum.HumanoidStateType.Climbing)
    end
end)

2 comments

0

How about trying print(workspace.CheetahCatPaw23.Humanoid:GetState()) while your character is climbing. Should help with troubleshooting.

0

(using the command bar while the game is running)

2 answers

✓ Accepted answer

Hello, CheetahCatPaw23!

Your script wasn't working because when any player joins, the variable changed, so it would only work to that player

Also, I don't know what .ChangeState does, so it can be an error on that line, but idk

local plr = game:GetService("Players")

script.Parent.Touched:Connect(function(hit)
    local isPlayer = plr:GetPlayerFromCharacter(hit.Parent) --Tryes to get player from the character
    if isPlayer then --Is a player
        player.Character.Humanoid.ChangeState(Enum.HumanoidStateType.Climbing)
    end
end)

Hope this helps

1 comment

0

Didnt work but thanks!

Humanoid.ChangeState is a function it should be written with ":" not "." like this

Humanoid:ChangeState()

and not like this

Humanoid.ChangeState()

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