Why doesn't the player jump when I make the player jump via script?

When a player drives into a part I have this script (below) activate. One problem, the player does not jump, everything else works fine, just the player does not jump. This is a problem because the player is still technically still in the car and thus cannot move.

Here is the script:

plrname = "roblox"
carname = "string"
vehicle = script.Parent
debounce = true
Instance.new("ObjectValue", script).Name = "vehicle"
local connection
function check(hit, vehicle)
	if debounce == true and plrname == carname and game.Players:FindFirstChild(plrname) and vehicle:FindFirstChild("custom") then
		--debounce = false
		workspace[plrname].Humanoid.Sit = false
		workspace[plrname].Humanoid.Jump = true
		local clone2 = vehicle:FindFirstChild("custom")
		local clone = game.ServerStorage.cars[vehicle.Name]:Clone()
		game.ReplicatedStorage.remoteevent:FireClient(game.Players[plrname], "camera", script.Parent.Parent.camera, script.Parent.Parent.Name, script.Parent.Parent.Parent.Name)
		clone.Parent = script.Parent.Parent.building.parking:FindFirstChild("1")
		clone:MoveTo(script.Parent.Parent.building.parking:FindFirstChild("1").Position)
		clone:PivotTo(clone:GetPivot() * CFrame.Angles(0, math.rad(180), 0))
		clone2.Parent = clone
		print(clone.Name)
		clone:FindFirstChild("ingarage").Value = true
		hit.Parent.Parent.Parent.Parent:Destroy()
		connection:Disconnect()
		wait(5)
		debounce = true
	end
end
connection = script.Parent.Touched:Connect(function(hit)
	if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
		plrname = hit.Parent.Name
		check(hit)
	elseif hit and hit.Parent.Name == "Body" and hit.Parent:FindFirstChild("car") then
		--vehicle = hit.Parent.Parent.car.Value
		vehicle = hit.Parent.car.Value
		print(vehicle.custom.Name)
		script.vehicle.Value = hit.Parent.Parent.Parent.Parent
		carname = vehicle.owner.Value
		check(hit, vehicle)
	end
end)

Here is the problem lines:

workspace[plrname].Humanoid.Sit = false
workspace[plrname].Humanoid.Jump = true

I had to rewrite this script because the old one was horrible, and, while the variable for the player name is different, the old one maes the player jump.

workspace[carname].Humanoid.Sit = false
workspace[carname].Humanoid.Jump = true

No it is not a problem with the variable, the variable is used to reference the player a multitude of other times in the script and it works. The problem lines work out of context, just in context they don’t want to work.

I don’t know much about this… but consider changing your Instance.new() to a local.
EX: local Obj = Instance.new(ā€œObjectValueā€, script)
Obj.Name = ā€œVehicleā€

1 Like

Try using

Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
1 Like

plrname isn’t the player … that is just a string.
workspace:FindFirstChild(plrname).Humanoid.Sit = false

Also really dislike all the .and .and .and .and added to a command. This kind of stuff makes debugging a program a nightmare. Try to pre-define the relative things up top, this is faster in the loop and more organized and efficient.

Ok, this isn’t related to the question but like

Why do you need to make it in the script? Can’t you just put an ObjectValue inside the script named vehicle?

sorry but that doesnt work. (character limit)

what

workspace[plrname].Humanoid.Jump = true

does is basically the same as FindFirstChild(), as its finding anything by the name of ā€˜plrname’ inside of workspace.

Sweet, nice and short. Didn’t know that. I was more talking about presetting some of them calls and not so much use lines like:

game.ReplicatedStorage.remoteevent:FireClient(game.Players[plrname], "camera",script.Parent.Parent.camera, script.Parent.Parent.Name, script.Parent.Parent.Parent.Name)

As that gets hard to debug.