Hello there! i’ve got a simple question about disabling two HumanoidStates, Swimming and Seated.
Looking for information through the Developer Forums, i’ve found a few posts mentioning that the Dead state needs to be disabled from Client and Server, as both target different parts, but these posts also mentioned there are states that can be disabled from the Client without the need of using a Server script.
My concern here is… Is this necessary for the Swimming and Seated states? currently, i’m disabling these states from Client and Server, but i’m not sure if maybe i shouldn’t be doing it, here are the scripts:
Client:
local char = script.Parent
local hum = char.Humanoid
hum:SetStateEnabled(Enum.HumanoidStateType.Seated, false)
hum:SetStateEnabled(Enum.HumanoidStateType.Swimming, false)
Server:
local Players = game:GetService("Players")
local function disableStates(plr)
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char.Humanoid
hum:SetStateEnabled(Enum.HumanoidStateType.Seated, false)
hum:SetStateEnabled(Enum.HumanoidStateType.Swimming, false)
end
Players.PlayerAdded:Connect(disableStates)
PD: They do work, but i’m not sure if i should be doing this.
couldn’t you fork the script from testing the game and then modify it? To answer your question, it’s necessary if you don’t want people to swim or such. It really depends.
Yes, i stated it works. I just want to know if i’m missing something, i.e. the Dead state requires both Client and Server because the client handles the parts falling apart, and the server handles the respawn. This is the reason i asked this question, because i want to know if it’s necessary, it does work, but what if i’m doing something completely unecessary? that’s also a possibility, and again, the reason of this post.
I believe this’ll work, until the player respawns. The server script will only disable the states the first time the player’s character spawns. You can fix this by changing the server script to the following:
Code
local Players = game:GetService("Players")
local function disableStates(char)
if char then
local hum = char:WaitForChild('Humanoid')
hum:SetStateEnabled(Enum.HumanoidStateType.Seated, false)
hum:SetStateEnabled(Enum.HumanoidStateType.Swimming, false)
end
end
Players.PlayerAdded:Connect(function(plr)
disableStates(plr.Character)
plr.CharacterAdded:Connect(disableStates)
end)
To answer your question:
Yes, for the seated state. EDIT: Nevermind, disabling the seated state actually appears to result in glitchy behavior regardless. It’ll still weld your character to the seat, but the animation won’t play and you can’t get up.
If you want to stop players from being able to sit in seats, just set the Seat.Disabled property to true.
After further testing, it turns out you don’t need to do this on the server after all. The original behavior that made me believe you had to set the property on both ends happens regardless. My apologies. I edited the original reply.