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

How to fire this function in a localscript?

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.

4 comments

0

You don't have to put it in a function. Just disable the script until it gets teleported into the player.

0

But I need it to be a function because I have that same first function run again later in the script.

1

You can check to see if something is added to the players Character with the ChildAdded event

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.

1 answer

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!

1 comment

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.

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