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

What do I do to disable jump for a few seconds when someone is forced to sit?

I have the following code for a banana peel. When someone touches it they are forced to sit, but they can get up instantly, as if they never touched it in the first place.

local touchedBanana = false
if touchedBanana == false then
	script.Parent.Touched:connect(function(hit)
		touchedBanana = true
		if game.Players:GetPlayerFromCharacter(hit.Parent) then
			hit.Parent.Humanoid.Sit = true
		end	
		touchedBanana = false
	end)
end

I would like to make it so that the player is forced to sit for 3 seconds, somehow disabling jump during that time.

4 answers

✓ Accepted answer

Here are two different methods on how to do it.

METHOD 1: Toggle the Humanoid's property, PlatformStand.

This will stop the user from moving or standing up, but upon testing you will see that the player is almost standing inside the ground.

ADVANTAGES:

  • Handled through 1 script
  • Simple
  • Works

DISADVANTAGES:

  • Player looks weird lol
local touchedBanana = false
local slipDelay = 3 -- how long before will be able to stand

script.Parent.Touched:connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
		if touchedBanana then return end
		local char = player.Character
		if char then
			local hum = char:FindFirstChildWhichIsA("Humanoid") 
			if hum then
				touchedBanana = true
				hum.Sit = true
				hum.PlatformStand = true
				delay(slipDelay,function()
					hum.PlatformStand = false
					touchedBanana = false
				end)
			end
		end		
    end 
end)

METHOD 2: Tell the client to disable player controls, taking away their power to stand. This way they can't move or do anything and are merely flopped until otherwise said

ADVANTAGES:

  • Player will actually remain sat
  • Efficient
  • Works

DISADVANTAGES:

  • Exploiters can reverse this
  • Handled through 2 scripts

SCRIPT INSIDE BANANA

local touchedBanana = false

local bananaEvent = game:GetService("ReplicatedStorage"):FindFirstChild("BananaSlip") or Instance.new("RemoteEvent", game:GetService("ReplicatedStorage"))
bananaEvent.Name = "BananaSlip"

local slipDelay = 3 -- how long before will be able to stand

script.Parent.Touched:connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
		if touchedBanana then return end
		local char = player.Character
		if char then
			local hum = char:FindFirstChildWhichIsA("Humanoid") 
			if hum then
				touchedBanana = true
				bananaEvent:FireClient(player, slipDelay)
				hum.Sit = true
				delay(slipDelay,function()
					touchedBanana = false
				end)
			end
		end		
    end 
end)

LOCALSCRIPT INSIDE StarterPack

local bananaSlip = game:GetService("ReplicatedStorage"):WaitForChild("BananaSlip")

bananaSlip.OnClientEvent:Connect(function(t)
	local controls = require(game:GetService("Players").LocalPlayer.PlayerScripts.PlayerModule):GetControls()
	controls:Disable()
	delay(t,function()
		controls:Enable()
	end)
end)

If this works, please don't forget to accept my answer.

Thanks in advance, R455

1 comment

0

Although I found another solution, your answer is also very helpful and it works :)

You can do just that by changing the humanoid's JumpPower

local touchedBanana = false
if touchedBanana == false then
    script.Parent.Touched:connect(function(hit)
        touchedBanana = true
        if game.Players:GetPlayerFromCharacter(hit.Parent) then
            hit.Parent.Humanoid.Sit = true
	    hit.Parent.Humanoid.JumpPower = 0
	    wait(3)
  	   hit.Parent.Humanoid.JumpPower = 50	
        end 
        touchedBanana = false
    end)
end

2 comments

0

Even with 0 JumpPower, I can still get up after "slipping". I've tried this before and had no success, sadly

0

What do you mean by "slipping"

You could use PlatformStand property of the humanoid

local touchedBanana = false
if touchedBanana == false then
    script.Parent.Touched:connect(function(hit)
        touchedBanana = true
        if game.Players:GetPlayerFromCharacter(hit.Parent) then
			hit.Parent.Humanoid.PlatformStand = true
			hit.Parent.Humanoid.Sit = true
			wait(3)
			hit.Parent.Humanoid.PlatformStand = false
        end 
        touchedBanana = false
    end)
end

Thank you for your answers! I actually managed to find a solution by myself. I should've closed this thread sooner, my apologies. To achieve the desired effect, all I did was anchor HumanoidRootPart for a short time. Again, I'm sorry I didn't say this sooner.

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