Hello everyone,
I am trying to subtract the position of a part, every time on a server event.
When i try to add position, it works. However when i try to subtract the position, it is not working.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
ReplicatedStorage:WaitForChild("RemoteEvent2").OnServerEvent:Connect(function()
game.Workspace.Folder.Union.Position = game.Workspace.Folder.Union.Position - Vector3.new(0.25,0,0)
-- subtract position is not working
end)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent2 = ReplicatedStorage:WaitForChild("RemoteEvent2")
local Part = game.Workspace.Folder.Union
RemoteEvent2.OnServerEvent:Connect(function(player)
Part.Position -= Vector3.new(0.25,0,0)
end)
I think you can try this. I tested it and it works for me. So you use the ‘-=’ symbols here.
Usually in a case like that, I’ve always had to take the current position, make the calculations, and create a new Vector3 with the new data. Something like this:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
ReplicatedStorage:WaitForChild("RemoteEvent2").OnServerEvent:Connect(function()
local pos = game.Workspace.Folder.Union.Position
game.Workspace.Folder.Union.Position = Vector3.new(pos.X - 0.25, pos.Y, pos.Z)
end)