Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Model Move Help? [2]

I'm trying to make a Model slowly move down for 3 seconds. Thank's to whoever helped me on the first question, but I just need it to slowly move down for 3 seconds, but I have to keep clicking it and it moves like 2 studs down:

function onClicked(playerWhoClicked)

local model = workspace.Tuner1.Lift --Model to move
local part = model:GetChildren()[1]
model.PrimaryPart = part

for i = 1,1,.01 do
    wait(i)
    model:SetPrimaryPartCFrame(model:GetPrimaryPartCFrame() - Vector3.new(0,3,0))
end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

2 answers

✓ Accepted answer

Please do not double post.

The problem is that you didn't have a debounce to your script, as well as the fact that you were waiting i seconds before re-iterating.. if you do that then the script will wait a lot more than it should before subtracting CFrames again.

local model = workspace.Tuner1.Lift --Model to move
local part,db = model:GetChildren()[1],false
model.PrimaryPart = part

script.Parent.ClickDetector.MouseClick:connect(function()
	if db == false then
		db = true
		for i = 1,100 do
			wait()
			model:SetPrimaryPartCFrame(model:GetPrimaryPartCFrame() - Vector3.new(0,.03,0))
		end
	db = false
	end
end)

6 comments

0

Ok, but what if I wanted it to automatically go down? With that one I have to spam click it

0

My bad, the for loop on line 8 was messed up. Try my edit.

0

Ok, so to stop it, it would be wait(3) then CFrame 0,0,0?

0

What? No, it will stop automatically.

0

Er, it doesn't

0

Nevermind, thank you.

function onClicked(playerWhoClicked)

local model = workspace.Tuner1.Lift --Model to move
local part = model:GetChildren()[1]
model.PrimaryPart = part

for i,v in pairs = 1,1,.01 do
    wait(i)
    model:SetPrimaryPartCFrame(model:GetPrimaryPartCFrame() - Vector3.new(0,3,0))
end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

3 comments

0

I put for i,v in pairs so since the numbers 1,1 are pairs

0

Ok, but Error on line 7? And yes, I made the = a == .

0

Line 7 is incorrect syntax. Use a numerical for loop.

This discussion is preserved as it was. New answers, comments, and votes are closed.