local Players = game:GetService("Players")
local sited = nil
local part = script.Parent.Part
local function goup(Part)
Part.Position += Vector3.new(0,20,0)
end
script.Parent.VehicleSeat:GetPropertyChangedSignal("Occupant"):Connect(function()
local humanoid = script.Parent.VehicleSeat.Occupant
if humanoid then
local character = humanoid.Parent
local player = Players:GetPlayerFromCharacter(character)
if player then
sited = player
if sited then
print("sitting")
script.Parent.RemoteEvent.OnServerEvent:Connect(function(player, movement)
if movement == "goUP" then
goup(part)
end
end)
end
return
end
end
if sited then
sited = nil
end
end)
local
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input)
if input == Enum.KeyCode.E then
script.Parent.RemoteEvent:FireServer("goUP")
end
end)
I want it, so whe player holds âEâ part goes up, but it isnât working
I think itâs because your first loop fires only when the playerâs Property changes, and if E isntâ being pressed then âsitedâ (do you mean sat?) gets set to nil.
This means (as @xXSanrioSlayer99 said) you need to make a separate remote event at the end.
game:GetService("RunService").RenderStepped:Connect(function()
if game:GetService("UserInputService"):IsKeyDown(Enum.KeyCode.E) == true then
script.Parent.RemoteEvent:FireServer("goUP")
end
end
also in your code:
UIS.InputBegan:Connect(function(input)
if input == Enum.KeyCode.E then
script.Parent.RemoteEvent:FireServer("goUP")
end
end)
you forgot to make âinputâ, âinput.KeyCodeâ.
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input)
if input == Enum.KeyCode.E then
script.Parent.RemoteEvent:FireServer("goUP")
end
end)
In the LOCAL script
with
game:GetService("RunService").RenderStepped:Connect(function()
if game:GetService("UserInputService"):IsKeyDown(Enum.KeyCode.E) == true then
script.Parent.RemoteEvent:FireServer("goUP")
end
end
Alright I was wrong in my previous post but this should be the solution to your problem.
SERVER
local Players = game:GetService("Players")
local sited = nil
local part = script.Parent.Part
local movement = 'none'
local function goup(Part)
Part.Position += Vector3.new(0,1,0)
end
local function godown(Part)
Part.Position -= Vector3.new(0,1,0)
end
script.Parent.VehicleSeat:GetPropertyChangedSignal("Occupant"):Connect(function()
local humanoid = script.Parent.VehicleSeat.Occupant
if humanoid then
local character = humanoid.Parent
local player = Players:GetPlayerFromCharacter(character)
if player then
sited = player
if sited == nil then
return
end
end
else
sited = nil
end
end)
script.Parent.RemoteEvent.OnServerEvent:Connect(function(player, move)
if player == sited then
print(movement)
movement = move
if movement == "goUP" then
goup(part)
end
if movement == "goDOWN" then
godown(part)
end
end
end)
LOCAL
local lastTick = tick()
game:GetService("RunService").Heartbeat:Connect(function()
local move = 'none'
if game:GetService("UserInputService"):IsKeyDown(Enum.KeyCode.E) == true then
move = "goUP"
end
if tick() > lastTick + 0.05 then
lastTick = tick()
script.Parent.RemoteEvent:FireServer(move)
end
end)
Put a print statement in each section to find out where the issue is.
For example in your Local Script put
if game:GetService("UserInputService"):IsKeyDown(Enum.KeyCode.E) == true then
move = "goUP"
print("E pressed")
end
I just noticed you are checking in the GetPropertyChanged function to see
if player then -- so checking to see if player is true
sited = player --making sited = player only if the above line is true
if sited == nil then --if sited == nil that means 2 lines above didn't find player = true?
return -- so you finish with sited == nil
end
end
else
sited = nil --you're setting sited to nil if there is a humanoid
end
Basically in the above function you are checking for a player if the VehicleSeat Property changes then setting sited to player, and then immediately setting sited to nil. That doesnât make sense.
Easy fix the local script doesnât have a player. Its just in workspace. Put a spawn pad down. Then put the model with the seat in starterplayer â startercharacterscripts