Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How could I make the click of a TextButton trigger an "animation" made through a script?

Asked by 9 years ago

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:

01local model = script.Parent
02local speed = 100 -- the speed it spins at, change this to how fast you want it to spin
03 
04local orig = script.Parent
05local rotation = 0
06local cf = orig:GetModelCFrame()
07 
08for i=1, 20 do
09model:TranslateBy(Vector3.new(0, 0.05, 0))
10wait()
11end
12 
13wait (2)
14local function ModelCFrame(Model,Frame)
15    local search,MidFrame,list = nil,Model:GetModelCFrame(),{}
View all 36 lines...

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:

1function tele()
2-- (THE CODE THAT I POSTED ABOVE)
3end
4script.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:

1if script.Parent.MouseButton1Down then
2-- (THE CODE THAT I POSTED ABOVE)
3end

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!

0
Is this in a Localscript? woodengop 1134 — 9y
0
No, it's just in a normal script. IronSpider671 50 — 9y

1 answer

Log in to vote
1
Answered by
Validark 1580 Snack Break Moderation Voter
9 years ago
1if script.Parent.MouseButton1Down then
2-- (THE CODE THAT I POSTED ABOVE)
3end

Remember, even though the above code makes sense to us Humanz, it does not make sense to the computer.

In an if-then statement, the stuff between the if and then is called a conditional. If the conditional equals true, the code runs, otherwise, it does not.

01if true then
02    --always runs this code
03end
04 
05if false then
06    --never runs this code
07end
08 
09if IronSpider671.AwesomenessLevel > 9000 then
10    --The computer turns "IronSpider671.AwesomenessLevel " into either true or false. If it is true, this code runs
11    print("WHAT!? 9000!?")
12end

The reason why your code doesn't work, is because when you tested it out, it was parented differently than it was when you tried to run it in the TextButton.

In other words, when you tested it, script.Parent = teleporter. When you copy and pasted, script.Parent = TextButton, and your script tried to animate the TextButton instead of the teleporter.

I removed "model" from the beginning of your script, since it is the same thing as orig.

Here is your script, I didn't look through it really, but I made it work I think:

01function tele()
02local teleporterName = "Teleporter" --Make sure this is the only object in Workspace with this name
03local speed = 100 -- the speed it spins at, change this to how fast you want it to spin
04 
05local orig = workspace:FindFirstChild(teleporterName,true)
06local rotation = 0
07local cf = orig:GetModelCFrame()
08 
09for i=1, 20 do
10orig:TranslateBy(Vector3.new(0, 0.05, 0))
11wait()
12end
13 
14wait (2)
15 
View all 41 lines...
0
Wow! Thanks, Validark! Really appreciate it! I'll tell my friend about this. He'll be delighted. Thanks again! You, sir, have an awesome day! IronSpider671 50 — 9y
0
You too! Make sure to hit "Accept Answer" if my answer was what you were looking for. Validark 1580 — 9y
Ad

Answer this question