Hello, I am working on a car system but ¿?
When player leaves, it can’t walk for some reason
video;
as you can see, walkspee is set to 16, and still can’t move!
No clue why.
This is the code that gives the local script to player;
DriveSeat:GetPropertyChangedSignal("Occupant"):Connect(function()
local occupant = DriveSeat.Occupant
if (occupant) then
local Player = game.Players:GetPlayerFromCharacter(occupant.Parent)
if (Player) then
lastPlayer = Player
if (Player.PlayerGui:FindFirstChild("carLocal")) then
return
end
local scriptt = game.ReplicatedStorage.Events.CarSystem.carLocal:Clone()
scriptt.Parent = Player.PlayerGui
scriptt.Car.Value = car
scriptt.Disabled = false
ConnectEvents(scriptt)
for i,v in pairs(car:GetDescendants()) do
if v:IsA("BasePart") then
v:SetNetworkOwner(Player)
end
end
end
else -- no occupant
if (lastPlayer) then
lastPlayer.PlayerGui.carLocal:Destroy()
end
game.ReplicatedStorage.Events.CarSystem.CloseCarUI:FireClient(lastPlayer)
for i,v in pairs(car:GetDescendants()) do
if v:IsA("BasePart") then
v:SetNetworkOwner(nil)
end
end
car.Chassis.VehicleSeat.EngineStart:Stop()
car.Chassis.VehicleSeat.Engine:Stop()
end
end)
It’s probably the local script thats causing the issue. I believe the local script uses the contextual action service to bind the wasd keys to driving the car while unbinding the original movement keys so you should check there.
Yeah I believe its something like this which is what I did for my controller before in a local script. Just unbind what you binded before when the humanoid is unseated.
function onSeated(isSeated, seat)
if isSeated then
print("I'm now sitting on: " .. seat.Name .. "!")
ContextActionService:BindAction("Move", onMove, false, FORWARD_KEY)
ContextActionService:BindAction("MoveBack", moveBack, false, BACKWARDS_KEY)
ContextActionService:BindAction("Right", rotateRight, false, RIGHT_KEY)
ContextActionService:BindAction("Left", rotateLeft, false, LEFT_KEY)
else
print("I'm not sitting on anything")
ContextActionService:UnbindAction("Move")
ContextActionService:UnbindAction("MoveBack")
ContextActionService:UnbindAction("Right")
ContextActionService:UnbindAction("Left")
end
end
--event for when player sits or not
humanoid.Seated:Connect(onSeated)
Is there a way to know if a local script is getting destroyed before it destroys?
To unbind actions
Tried this but doesn’t prints uh oh, so doesnt fires D:
Well, yeah actually according to my research, didn’t think about that good catch
Yeah just do the manual unbinding like what’s been written before. The good thing about this in the scenario is that it doesn’t error so you can just unbind the moment you leave the seat.