I have a tool and when a player presses a button the tool will change it's position, but the tool will only move in one direction and will not head back to it's original spot.

Function moves tool to it's new spot and records the positions in two arrays

local gripPosArray = {}
local gripRightArray = {}

function scopeAnimationTo()
	for i = 1, 20 do
		wait()
		script.Parent.GripPos = script.Parent.GripPos + Vector3.new(0,0,-.025)
		table.insert(gripPosArray,i,script.Parent.GripPos)
		script.Parent.GripRight = script.Parent.GripRight + Vector3.new(0,0,-.1)
		table.insert(gripRightArray,i,script.Parent.GripRight)
	end
	print(script.Parent.GripPos)
end

Function moves the tool back to origin using the array positions

function scopeAnimationFrom()
	for i = 1, 20 do
		wait()
		script.Parent.GripPos = gripPosArray[20-i]
		print(script.Parent.GripPos)
		script.Parent.GripRight = gripRightArray[20-i]
	end
	print(script.Parent.GripPos)
end


4 comments

0

Could you supply the arrays in your script as well? Are you ever calling this function? And is this a localscript?

0

This is in a regular script so it won't clash with filtering enabled, these functions are called whenever a person right clicks

0

Could you supply the arrays in your script please.

0

I feel really dumb, I forgot to change a boolean after the "scopeAnimationTo" so it kept running, sorry for wasting your time.