What do you want to achieve?
I want to make it so a player cannot get up after being sat down.
What is the issue?
What solutions have you tried so far?
I looked at a few posts on the devforum.
Basically I’m making a game called Sardines, if you don’t know what the game Sardines is, it’s a game where someone hides, then other people need to find the hider. When someone finds the hider, they join them in hiding.
And I want to be able to make it so you sit down and wont be able to get back up because you’re hiding.
local Notif = require(script.Parent.Notifier)
game.ReplicatedStorage.Hide.OnServerEvent:Connect(function(hider)
print(hider.UserId)
if hider.UserId == game.ReplicatedStorage.HiderId.Value then
-- If the user is the real hider
hider.Character.Humanoid.JumpPower = 0
hider.Character.Humanoid.WalkSpeed = 0
hider.Character.Humanoid.Sit = true
for i,v in pairs(hider.Character:GetChildren()) do
if v:IsA("BasePart") then
else
warn(v.Name.." is not a basepart.")
end
end
else
-- Uhoh
hider:Kick("You've been detected for exploiting.")
end
end)
Everything in the script above works, however the player can still use the space bar to get back up.
If you don’t want the player to be able to get back up, you might consider using PlatformStand instead of Sit. That will essentially do the same thing. If you still want the animation for sitting, you could play that animation on top (or maybe some sort of hiding animation instead!)
There are multiple soloutions for this. @Barothoth was right, but if you would like to keep the classic sit in your game, then you could make the player’s JumpPower 0 once you want them to remain sitting. When is the JumpPower 0, the player won’t be able to get up.
I did this by forcing “Sit” to be true and “Jump” to be false.
game.Players.PlayerAdded:Connect(function(p)
p.CharacterAdded:Connect(function(c)
if c.Humanoid.Sit == true then
while wait(.0001) do
c.Humanoid.Jump = false
c.Humanoid.Sit = true
end
end
end)
end)
And this is where I placed the script:
There might be a more efficient way of doing this, but this method is functional.
Hello!
This function would work, however you are using while wait(.0001) do, which is not really a best thing what you can do.
More about this topic can be found over here: Avoiding wait() and why