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.