So i'm using a proximity prompt to make a player sit in a vehicle seat.
This is the Sit script
local proximityPromt = script.Parent local seat = proximityPromt.Parent seat:GetPropertyChangedSignal("Occupant"):Connect(function() if seat.Occupant then proximityPromt.Enabled = false else proximityPromt.Enabled = true end end) proximityPromt.Triggered:Connect(function(player) seat:Sit(player.Character.Humanoid) end)
The UnSit script is inside the vehicle seat not the prompt.
local Players = game:GetService("Players") local userInputService = game:GetService("UserInputService") userInputService.InputBegan:Connect(function(input, gameProcessedEvent) if input.UserInputType == Enum.UserInputType.Keyboard then if input.KeyCode == Enum.KeyCode.G then Players.Character.Humanoid.Sit = false end end end)
It supposed to make the humanoid not sit anymore after you press G. But it doesn't work and there is nothing in the output window. I tried using a local script, tried adding the code to the sit script it just doesn't work, Nothing happens when i press the keycode.
UserInputService does not work on server scripts. You will need to listen for a key press on a LocalScript and tell the server to kick the character from its seat using a RemoteEvent
First, put a RemoteEvent in ReplicatedStorage, where both the server and the client can see it
LocalScript:
local userInputService = game:GetService("UserInputService") local ReplicatedStorage = game:GetService("ReplicatedStorage") userInputService.InputBegan:Connect(function(input, gameProcessedEvent) if input.UserInputType == Enum.UserInputType.Keyboard then if input.KeyCode == Enum.KeyCode.G then -- tell any server scripts that are listening to a RemoteEvent called "GetUpFromSeat" to run ReplicatedStorage.GetUpFromSeat:FireServer() end end end)
Server script:
local ReplicatedStorage = game:GetService("ReplicatedStorage") ReplicatedStorage.GetUpFromSeat.OnServerEvent:Connect(function(player) -- when you fire a RemoteEvent from a client, the player who fired it is passed to the server by Roblox automatically player.Character.Humanoid.Sit = false end)