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

How to fire this function in a localscript?

Asked by
emite1000 335 Moderation Voter
9 years ago

Okay, so I have a LocalScript that gets cloned into the Player's PlayerGui when they click a button. As soon as it is copied into the PlayerGui, I want it to immediatly start running the first function in it. But I don't know how to get it to do that? If I just call the function first thing, it doesn't work because the function is underneath in the script.

Does anyone know how I would get around this problem? Is there some event that can detect when a LocalScript is placed in a Player? Or any other Event that could help me in this situation?

Thanks in advance.

0
You don't have to put it in a function. Just disable the script until it gets teleported into the player. EzraNehemiah_TF2 3552 — 9y
0
But I need it to be a function because I have that same first function run again later in the script. emite1000 335 — 9y
1
You can check to see if something is added to the players Character with the ChildAdded event alphawolvess 1784 — 9y
0
But the LocalScript won't start running until it is inside the Character. So by the time it is cloned in there and starts running, it (the Child) will already be added. emite1000 335 — 9y

1 answer

Log in to vote
0
Answered by
emite1000 335 Moderation Voter
9 years ago

I figured it out. In the script that cloned the the LocalScript into the PlayerGui I had it wait and the change the name of an object. In the LocalScript I used the Changed event to listen for the object to be changed and then Connected to the function.

Anyway I solved that problem but now it's causing the function to run twice for some reason. Thanks for all the help guys!

0
You know, local scripts don't run until they become a descendant of a player, or client. Just clone in the local script normally and it will work fine. aquathorn321 858 — 9y
Ad

Answer this question