Model doesnt wanna move

So I am making a button which can move the part up and down here’s how the code looks

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("PartClicked")

local originalCFrame = script.Parent.PrimaryPart.CFrame

remoteEvent.OnServerEvent:Connect(function(player, y, name)
	if script.Parent.Name == game.Workspace.PartMoving.Value then
		
	if name == "Up" or name == "MassUp" then
		
			local newCFrame = originalCFrame + Vector3.new(0, y, 0)
			originalCFrame = newCFrame
		script.Parent:SetPrimaryPartCFrame(newCFrame)
		end

	elseif name == "Down" or name == "MassDown" then

		local newCFrame = originalCFrame + Vector3.new(0, -y, 0)
		originalCFrame = newCFrame
		script.Parent:SetPrimaryPartCFrame(newCFrame)

end
end)

Now it’s really wierd, the down moves it like 20 studs up and up moves it up one stud and sometimes it moves it back where it originally was. Here’s the code from a locla script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("PartClicked")
local y = 0
local name = script.Parent.Name

script.Parent.Activated:Connect(function()
	y = y + 1
	remoteEvent:FireServer(y, name) 
end)
Any help is appreciated and I've verified that the names are correctly and the down button is exactly as the local scirpt except for it changine y to y - 1

Just throwing out a suggestion here or two. Would PivotTo and GetPivot be better than SetPrimaryPart?
Maybe add / decrease from current Position? Something like:

y = 1
script.Parent:PivotTo(script.Parent:GetPivot() + Vector3.new(0,y,0))

Yes it does work better I fixed the line with Vector3.new but like the down thingy does not work with your line script.Parent:PivotTo(script.Parent:GetPivot() + Vector3.new(0,-y,0))

Sorry for that little error.
Assuming the down script is the same script as up, just different name / Parent. The only thing I could think of is - Vector.new / + Vector.new . Showcased in code below. y is positive but the vector.new is either - / + .

remoteEvent.OnServerEvent:Connect(function(player:Player, y:number, name:string)
		if script.Parent.Name == game.Workspace.PartMoving.Value then
			if name == "Up" or name == "MassUp" then
				script.Parent:PivotTo(script.Parent:GetPivot() + Vector3.new(0,y,0))
			end
		elseif name == "Down" or name == "MassDown" then
			script.Parent:PivotTo(script.Parent:GetPivot() - Vector3.new(0,y,0))
		end
	end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.