How do I force a player to jump after closing a GUI

Main Info

I have tried looking into Google and the forum, but the script isn’t working. I have tried many, including the one below. I’m trying to force a player to jump when they click the close button on a GUI. The GUI is closing, but the player isn’t jumping. I would also like to add a cooldown for them before seating in any seat again.

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Parent.Visible = false
	game.Players.LocalPlayer.Character.humanoid.jump = true
end)

Lua is case-sensitive (capitalization matters), so…

…and…

…wouldn’t work. Here’s a working script:

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Parent.Visible = false
	game.Players.LocalPlayer.Character.Humanoid.Jump = true
end)

Hope this helps!
Fizzitix

1 Like

It seems to not be working the way we expect. My player is not jumping.
image

1 Like

There’s another method that uses Humanoid:ChangeState().

Try this script:

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Parent.Visible = false
	game.Players.LocalPlayer.Character.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end)
2 Likes

Thank you so much for fixing it. I was wondering how do I enable the GUI to appear ONLY when the player sits on a chair and make it so that they can’t jump while seated?

1 Like

The humanoid has a Sitting property you can listen to, and to disable jumping, you can simply set the JumpPower property to 0.

Example script:

game.Players.LocalPlayer.Character.Humanoid:GetPropertyChangedSignal("Sit"):Connect(function()
    if game.Players.LocalPlayer.Character.Humanoid.Sit == true then
	    script.Parent.Parent.Visible = true
	    game.Players.LocalPlayer.Character.Humanoid.JumpPower = 0
    end
end)

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Parent.Visible = false
	game.Players.LocalPlayer.Character.Humanoid.JumpPower = 50
	game.Players.LocalPlayer.Character.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end)

Hope this helps,
Fizzitix

(Edit: I’ve significantly improved the script above, please copy/paste it again)
(Edit 2: I noticed errors in the code and fixed them, please copy/paste it again)

variables help a lot guys

local player = game.Player.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character.Humanoid
local holder = script.Parent.Parent

humanoid:GetPropertyChangedSignal("Sit"):Connect(function()
    if humanoid.Sit then
	    holder.Visible = true
	    humanoid.JumpPower = 0
    end
end)

script.Parent.MouseButton1Click:Connect(function()
	holder.Visible = false
	humanoid.JumpPower = 50
	humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end)
2 Likes

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