Forcing a player to jump does not work for me

Hi! I currently have a script that when a player sits in a seat, it checks if they’ve been assigned as a staff member. If they haven’t, then it will simply jump them out of the seat. However, the jumping part doesn’t work.

My code to jump the character is:

player.Character.Humanoid.Jump = true

By the way, it is not because the character/humanoid/player is nil as there are no errors in the output. I’ve also tried logging something in the console if the player is not a staff, and it logs it but it does not jump the player.

player.Character.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)

1 Like

I have also tried that, no errors in the output and it doesn’t work.

Make sure you define the character and player properly. It works for me!

As I said, it is not because the player/character/humanoid is nil. There are 0 errors in the output, which makes it unlikely.

Could you show us the whole script?

Sure!

local gui

local allowedRoles = {"GA", "Flight Host"}

function giveTool(weldChild)
	local findHuman = weldChild.Part1.Parent:FindFirstChild("Humanoid")
	if findHuman ~= nil then
		local player = game.Players:GetPlayerFromCharacter(findHuman.Parent)
		if (player ~= nil) then
			local staffRole = game.ServerStorage.Staff:FindFirstChild(tostring(player.UserId))
			
			if staffRole ~= nil and table.find(allowedRoles, staffRole.Value) then
				gui = script.Parent["System"]:Clone() -- Change toolname to what tool you want to be given
				gui.Parent = player.PlayerGui
				gui.Seat.Value = script.Parent
			else
				print("yes")
				print(player.Character.Name)
				player.Character.Humanoid.Jump = true
			end
		end
	end
end

function removeTool()
	if (gui ~= nil) then
		gui:Destroy()
	end
end

script.Parent.ChildAdded:Connect(giveTool)
script.Parent.ChildRemoved:Connect(removeTool)

And by the way, this is a modified version of the original script.

Are you using a regular seat? Or some modified version?

I’m using a VehicleSeat, could that be the problem?

Try using a regular seat instead of a vehicle seat, it could change something.

Yes, but I’m forcing the player out of a vehicle. How can I use a normal seat?

Okay, I used a normal seat instead of a vehicle seat. I have the same problem.

change

player.Character.Humanoid.Jump

to

local ch = player.Character
repeat wait() until ch ~= nil
local hum = ch.Humanoid
hum:ChangeState(Enum.HumanoidStateType.Jumping)

Nope, I still have the exact same problem.

Oh you’re forcing them out of a vehicle? Then keep it.

local seat = script.Parent
local occupant
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if seat.Occupant then
		print(seat.Occupant.Parent) --prints player's name
       --code
	else
		--code
	end
end)
repeat wait() until ch

I don’t think that using a repeat loop is a good idea to wait for the character, there is a function that yields until the character exists, instead of the loop you can do

local character = player.Character or player.CharacterAdded:Wait()`

This does not work either. 30 charasss

Anything in the output?..

Okay, put your modified script below so we know what’s going on VVV

local seat = script.Parent
local occupant

local allowedRoles = {"GA", "Flight Host"}

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if seat.Occupant then
		occupant = seat.Occupant.Parent
		
		local player = game.Players:GetPlayerFromCharacter(occupant)
		
		if (player ~= nil) then
			local staffRole = game.ServerStorage.Staff:FindFirstChild(tostring(player.UserId))
			
			if staffRole ~= nil and table.find(allowedRoles, staffRole.Value) then
				local GUI = seat.System:Clone()
				GUI.Parent = player.PlayerGui
				GUI.Seat.Value = seat
			else
				player.Character.Humanoid.Jump = true
			end
		end
	else
		local GUI = game.Players:GetPlayerFromCharacter(occupant).PlayerGui:FindFirstChild("System")
		
		if GUI then
			GUI:Destroy()
		end
	end
end)