Well, you can check every time a player is seated or unseated with this:
local character = --Path for character
local humanoid = character:WaitForChild("Humanoid")
local function onSeated(isSeated, seat)
if isSeated then
-- Put a connection with the uis
else
-- player is not sitting anymore (idk if you need this)
end
end
humanoid.Seated:Connect(onSeated)
local character = --Path for character
local humanoid = character:WaitForChild("Humanoid")
local Connection = nil
local function onSeated(isSeated, seat)
if isSeated then
Connection = UIS.InputBegan:Connect(function(input, gameProcessedEvent)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.W then
CannonSeat.Parent.PrimaryPart.CFrame = CannonSeat.Parent.PrimaryPart.CFrame + CannonSeat.Parent.PrimaryPart.CFrame.LookVector
end
end
end
else
Connection:Disconnect()
end
end
humanoid.Seated:Connect(onSeated)
(I added the remaining code and added a connection/disconnect thingy)
You can also check if the user is seated with Humanoid.Seated
Thanks for the help, I realised that the reason why it wasn’t working with your script was because I needed to put it in starter character scripts instead of starter player scripts