So, I'm working on a game with a friend. I came across a problem when I was making a teleporter thing. I was going to make a teleporter GUI in which if you clicked "Confirm", the teleporter itself would have an "animation", or in other words hover, spin and then come back down. Now, I have the script for the animation, which is:
local model = script.Parent
local speed = 100 -- the speed it spins at, change this to how fast you want it to spin
local orig = script.Parent
local rotation = 0
local cf = orig:GetModelCFrame()
for i=1, 20 do
model:TranslateBy(Vector3.new(0, 0.05, 0))
wait()
end
wait (2)
local function ModelCFrame(Model,Frame)
local search,MidFrame,list = nil,Model:GetModelCFrame(),{}
search=function(a)
for n,o in pairs(a:GetChildren())do
if(o:IsA("BasePart"))then
table.insert(list,o)
end
search(o)
end
end
search(Model)
for n,o in pairs(list)do
o.CFrame=Frame*MidFrame:toObjectSpace(o.CFrame)
end
end
local i = 0
while(wait()) and i < 151 do
i = i + 1
rotation = rotation+(speed/5)
if(rotation>360)then rotation = 0 end
ModelCFrame(orig,cf*CFrame.Angles(0,math.rad(rotation),0))
end
Now, this script works. I tested it and the animation works flawlessly. Great! Now, for the next part, I had to make this "animation" run after the "Confirm" button. So, I basically copied and pasted the above code into a script in the TextButton, put an OnClick function around it and connected the function to MouseButton1Down to the "Confirm" TextButton. It looked something like this:
function tele()
-- (THE CODE THAT I POSTED ABOVE)
end
script.Parent.MouseButton1Down:connect(tele)
Turns out that it didn't work. I tried and experimented with different changes. Nothing. Then, on a whim, I tried to use an if statement to do this (I had no idea what I was doing, so don't blame me if it's horrendously wrong D:) and also failed. It looked something like this:
if script.Parent.MouseButton1Down then
-- (THE CODE THAT I POSTED ABOVE)
end
That failed as well. So, at this point, my friend and I are at a dead end. We have no idea what to do now, and we would really appreciate if someone could help us. And in case you want to see the end result of our game, look up the users, UsedMail (my friend) and/or IronSpider671(me) on ROBLOX. Thanks!

2 comments
Is this in a Localscript?
No, it's just in a normal script.