:SetStateEnabled() not working

i want to remove climbing from my game. I had tried finding the character and humanoid through startercharacterscripts and starterplayerscripts, but both did not work. This is my final script in ServerScriptService to try to remedy this, but it also did not work.

game.Players.PlayerAdded:Connect(function(p)
	p.CharacterAdded:Connect(function(c)
		local hum = c:WaitForChild("Humanoid")
		print("humanoid found")
		hum:SetStateEnabled(Enum.HumanoidStateType.Climbing,false)
		print("BOOOO!!!! NO CLIMBING")
	end)
end)

both print statements fire, so it is very confusing on why nothing happens.

1 Like

Here try this:

local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")

Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        local hum = character:WaitForChild("Humanoid")
        hum:SetStateEnabled(Enum.HumanoidStateType.Climbing, false)
    end)
end)

Workspace.DescendantAdded:Connect(function(descendant)
    if descendant:IsA("Model") and descendant:FindFirstChild("Humanoid") then
        local hum = descendant:FindFirstChild("Humanoid")
        hum:SetStateEnabled(Enum.HumanoidStateType.Climbing, false)
    end
end)

This script uses the DescendantAdded event to find all descendants of the Workspace that are models and have a Humanoid child. For each of these models, it sets the Humanoid property to disable climbing.

Note that this script will only run on the server, and it will only update the Humanoid properties for characters that are in the Workspace. If you want to update the Humanoid properties for characters that are in the client’s view, you’ll need to use a different approach.

I hope this helps! Let me know if you have any further questions.

Does doing it on the client really not work? Its best way to set it according to a bunch of people.

this is good for my use case, but in case i ever need npcs to climb, how would i let this script do so?

i thought doing it on client wouldn’t work because it wouldn’t replicate. maybe i can try that.

Roblox replicates almost anything related to a player’s character from client to the server

wouldn’t that contradict with filterenabled?

its one of the only exceptions

To allow NPCs to climb, you’ll need to modify the script to check whether the character is an NPC or a player. One way to do this is to add a custom property to the NPC models that indicates whether they should be able to climb.

Here’s an updated script that adds a check for a custom property called NPCCanClimb:


local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")

Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        local hum = character:WaitForChild("Humanoid")
        if character:FindFirstChild("NPCCanClimb") and character.NPCCanClimb.Value then
            hum:SetStateEnabled(Enum.HumanoidStateType.Climbing, true)
        else
            hum:SetStateEnabled(Enum.HumanoidStateType.Climbing, false)
        end
    end)
end)

Workspace.DescendantAdded:Connect(function(descendant)
    if descendant:IsA("Model") and descendant:FindFirstChild("Humanoid") then
        local hum = descendant:FindFirstChild("Humanoid")
        if descendant:FindFirstChild("NPCCanClimb") and descendant.NPCCanClimb.Value then
            hum:SetStateEnabled(Enum.HumanoidStateType.Climbing, true)
        else
            hum:SetStateEnabled(Enum.HumanoidStateType.Climbing, false)
        end
    end
end)

To use this script, you’ll need to add a NPCCanClimb property to the NPC models. You can do this by creating a new IntValue property in the NPC model’s properties, and setting its value to 1 to allow climbing or 0 to prevent climbing.

For example, if you have an NPC model called NPC, you can add a NPCCanClimb property like this:

  1. Open the NPC model in the Roblox Studio.
  2. In the Properties panel, click on the “+” button to add a new property.
  3. Select “IntValue” as the property type.
  4. Name the property “NPCCanClimb”.
  5. Set the value of the property to 1 or 0 as desired.

By using this custom property, you can easily control whether NPCs can climb or not, and you can modify the script to suit your specific needs.

i used a localscript in startergui where the localplayer’s character’s humanoid has climbing disabled and it seemed to work. thanks for helping!

1 Like

No problem! If it worked, make it as a solution so others with the same problem can use this script

Be careful when putting anything other than gui elements in StarterGui as they’ll reset whenever the player dies/resets

If they’re inside of a ScreenGui, you can set the ResetOnDeath value inside of the ScreenGui to false so it stays on the screen.

I know it’s already solved but it’s a bit funny that server scripts won’t work on a player character despite we all believing it should, however, i have a theory that if you take the player character and set the ownership to nil, do the necessary changes and then set the ownership back to the player, it should work.

doesn’t network ownership mean how much the client can control over physics compared to server? player input and stuff is dependent as it comes diretly from the client, so theoretically that would mean the client would lose control of the player.

yeah, you are right, i just had that theory for a while now but never tested it until now, but i found another way to fix it using 2 scripts:

Server Script:

local Players = game:GetService("Players")
local LocalScript = script:FindFirstChildWhichIsA("LocalScript")

Players.PlayerAdded:Connect(function(player)
	player.CharacterAppearanceLoaded:Connect(function(character)
		local hum = character:WaitForChild("Humanoid")
		if character:FindFirstChild("NPCCanClimb") and character.NPCCanClimb.Value then -- can players be npcs?, i am a npc irl.
			hum:SetStateEnabled(Enum.HumanoidStateType.Climbing, true)
		else
			local Clone = LocalScript:Clone()
			Clone.Parent = character
			wait(1)
			Clone:Destroy()
		end
	end)
end)

Local Script:

game:GetService("Players").LocalPlayer.Character.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Climbing,false)

Should be something like this:
image

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.