Sorry this script is probably pretty messy, still learning and the tabs don’t appear in the post.
The issue I have is that there are 3 similar LocalScripts in my StarterCharacterScripts folder like the one below. Each controls particular kinds of vehicles in the Workspace; Dump Trucks, Bulldozers and Front-End Loaders. It’s a one player game (due to lag with many moving Parts in multi-player games.
Here’s the issue, in Studio when I jump off a VehicleSeat the controllable parts of my vehicles stay where they were left (ie: dump truck bed stays at its last position, loader controls stay at their positions, etc.) but when I play the game on the website I leave the seat and the controls go back to their original position and when I get back in the seat the parts go back to where they were before I jumped out the first time.
I’ve tried setting the values to nil so you don’t keep controlling the vehicle after you leave but that doesn’t help the problem, the vehicles still reset when you leave the seat and go back to their last settings when you touch the seat.
Like I said the other scripts are similar, they just reference different controls/welds/hingeconstraints/lights.
Why is this working great in Studio and not in game?
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:wait()
local humanoid = character:WaitForChild(“Humanoid”)
local UIS = game:GetService(“UserInputService”)
local dump, door, step, smoke --references to the current seat’s controls
local l1, l2, l3, l4, l5, r1, r2 --references light controls
local working --last pressed KeyCode
humanoid.Seated:connect(function(active, seat)
if active then
wait(.1)
working = false
if seat:FindFirstChild(“Attachment”) then – safe to assume it is a Dump Truck
–print(‘Player sat on Dump Truck seat.’)
dump = seat.Parent.Dump.Motor
dump.DesiredAngle = dump.CurrentAngle
door = seat.Parent.Door.HingeConstraint
step = seat.Parent.Parent.Steps.Step.HingeConstraint
smoke = seat.Parent.Smoke.ParticleEmitter
l1 = seat.Parent.Light1
l2 = seat.Parent.Light2
l3 = seat.Parent.Light3
l4 = seat.Parent.Light4
l5 = seat.Parent.Light5.SpotLight
r1 = seat.Parent.Red1
r2 = seat.Parent.Red2
door.TargetAngle = 0
step.TargetAngle = -165
wait(1)
smoke.Enabled = true
end
elseif dump then – test for dump just to be safe (i.e. if they got up off a non-dump truck seat, I don’t want the script to crash)
–print(‘Player left Dump Truck seat.’)
–reset and clear dump/door/step when they leave the seat
dump.DesiredAngle = dump.CurrentAngle
smoke.Enabled = false
l1.Material = “Ice”
l2.Material = “Ice”
l3.Material = “Ice”
l4.Material = “Ice”
l5.Enabled = false
r1.Material = “Slate”
r2.Material = “Slate”
door.TargetAngle = 50
step.TargetAngle = 0
print("Dump: " … dump.CurrentAngle)
–[[dump, door, step, smoke, l1, l2, l3, l4, l5, r1, r2, working = nil
tried making this active so the controls aren’t available after
getting off the seat but it resets the dump angle back to 0 ]]
end
end)
UIS.InputBegan:connect(function(InputObject,gameProcessedEvent)
if dump then – only do anything if they’re sitting in the dump truck seat
if UIS:IsKeyDown(Enum.KeyCode.R) then
–print"Truck dump up"
wait()
working = Enum.KeyCode.R
dump.DesiredAngle =1.1
if dump.DesiredAngle<0.001 then dump.DesiredAngle=0.01 end
elseif UIS:IsKeyDown(Enum.KeyCode.F)then
–print"Truck dump down"
working = Enum.KeyCode.F
wait()
dump.DesiredAngle = 0
elseif UIS:IsKeyDown(Enum.KeyCode.L)then
–print"Truck lights"
wait()
if l5.Enabled == true then
l1.Material = “Ice”
l2.Material = “Ice”
l3.Material = “Ice”
l4.Material = “Ice”
l5.Enabled = false
r1.Material = “Slate”
r2.Material = “Slate”
else
l1.Material = “Neon”
l2.Material = “Neon”
l3.Material = “Neon”
l4.Material = “Neon”
l5.Enabled = true
r1.Material = “Neon”
r2.Material = “Neon”
end
end
wait()
end
end)
UIS.InputEnded:connect(function(InputObject,gameProcessedEvent)
if dump then – only do anything if they’re sitting in the dump truck seat
if InputObject.KeyCode == working then
–print"Dump Truck input Stopped"
working = false
dump.DesiredAngle = dump.CurrentAngle
end
end
end)