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

Help with a translating model?

I want a gate (Model) that slides into one position on click and slides back into its original position on second click. almost everything works well except for when i change the ".01" to anything different, it doesn't open nor close anymore.

script.Parent.ClickDetector.MouseClick:connect(function()
	local state = script.Parent.Parent.State
	if state.Value == false then
		state.Value = true
		local Gate = script.Parent.Parent.Gate
		for i = 0, .7, .01 do
			Gate:SetPrimaryPartCFrame(Gate:GetPrimaryPartCFrame() * CFrame.new(0,0,-i))
		end
	else
		state.Value = false
		local Gate = script.Parent.Parent.Gate
		for i = 0, .7, .01 do
			Gate:SetPrimaryPartCFrame(Gate:GetPrimaryPartCFrame() * CFrame.new(0,0,i))
		end
	end			
end)

2 comments

0

Would you mind telling us what you are changing it to?

0

I'm changing it to "1"

1 answer

✓ Accepted answer

Based on you telling me you are changing it to 1, here is the problem

your for loop takes 3 arguments: i, the ending number and the increment (These are not their exact names, just what they are)

your code that you posted goes up by .01 up to .7 every time, starting at 0. This works because both i and the increment are smaller than the end.

when you change it to 1, it won't work well because your asking it to go from 0 to 1 on the first round. since 1>0.7, the loop has executed the amount of times you asked it to and will end.

1 comment

0

thanks, i'm not very good with the "for" syntax

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