Why moving block isnt working

server

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

get rid of this

and put this at the end of your script

script.Parent.RemoteEvent.OnServerEvent:Connect(function(player, movement)
	if sited and movement == "goUP" then
		goup(part)
	end
end)
3 Likes

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.

1 Like

It still doesn’t work

(30 words)

I think I can help.
local

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”.

1 Like

Where should I put that thing?

Yeah my bad, but even that I changed it, it still doesn’t work

You need to replace

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
1 Like

Still nothing

(30 words words words)

Tell me what everything is parented under please.

1 Like

Of I figured it out. Aswell as what I mentioned previously you forgot to connect the remote event to anything.

1 Like

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)
1 Like

Idk am I doing something wrong, but it doesnt work

Please show us a screenshot of where your scripts are located in your Workspace window as @RayK_iv asked a couple hours ago.

1 Like

Still need help

(30 wordswords)

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.

2 Likes

Not the best way to do this, it is as basic an example as you can get but at least it works flying the seat around.

FlyingSeat_Baseplate.rbxl (45.1 KB)

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

1 Like

I already addressed all that in post #11

2 Likes

What print outputs are you getting when the player sits in the VehicleSeat?

1 Like