How to move a part position

I’m trying to make a part move from different position every time remote event is fired.
The problem is I don’t know how to move it.

local Part = game.Workspace:FindFirstChild("Part")
local RE = game.ReplicatedStorage:WaitForChild("RemoteEvent")

local YValue = (-10)

RE.OnServerEvent:Connect(function()
      Part.Position = Vector.new(0, YValue, 0)
end)

Will this work?

1 Like

Try this

local Part = game.Workspace:FindFirstChild("Part")
local RE = game.ReplicatedStorage:WaitForChild("RemoteEvent")

local YValue = (-10)

RE.OnServerEvent:Connect(function()
      Part.Position = Vector3.new(0, (Part.Position + YValue), 0)
end)
3 Likes

This will work:

local Part = game.Workspace:FindFirstChild("Part")
local RE = game.ReplicatedStorage:WaitForChild("RemoteEvent")

local YValue = -10

RE.OnServerEvent:Connect(function()
      Part.Position = Vector3.new(0, Part.Position.Y + YValue, 0) 
end)

The main reason your code didn’t work was because you forgot to put “3” at the end of “Vector”

3 Likes

The other scripts could be improved. Here is the way I would do it:

local Part = game.Workspace:FindFirstChild("Part")
local RE = game.ReplicatedStorage:WaitForChild("RemoteEvent")

local YValue = -10

RE.OnServerEvent:Connect(function()
      Part.Position += Vector3.new(0, YValue, 0) 
end)
1 Like

The reason I didn’t do “-=” is because there’s no need to, it’ll just make it harder to understand and your script won’t work since you forgot to change “Vector” to " Vector3".

1 Like

I fixed the Vector → Vector3 thing

The fact that OP mentioned

every time remote event is fired

Indicates that they want it to be able to occur multiple times. This would lend itself to allowing the value to go down incrementally, which is why I feel -= or += should be used

3 Likes

Thank for all the replies!
A bit of edit, and…my work is done.

local Part = game.Workspace:FindFirstChild("Part")
local RE = game.ReplicatedStorage:WaitForChild("RemoteEvent")

local YValue = (10)

RE.OnServerEvent:Connect(function()

  Part.Position = Vector3.new(Part.Position.X, (Part.Position.Y - YValue), Part.Position.Z)
  print("Succes")
  print(Part.Position)

end)
1 Like

Didn’t notice that earlier. Thank for pointing it out.

Part.Position = Vector3.new(Part.Position.X, (Part.Position.Y - YValue), Part.Position.Z)

This line here could be replaced by simply:

Part.Position -= Vector3.new(0, YValue, 0)
1 Like