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

Script functions when Character loads?

Asked by 8 years ago

Is their a way to make the script instantly run the second the character has loaded?

2 answers

Log in to vote
0
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
8 years ago

You can make a script run on character load by using the CharacterAdded event of player. This is fired whenever the player respawns or changes. It would look something like,

game.Players.PlayerAdded:connect(function(plr) --Get the player from this event.
    plr.CharacterAdded:connect(char) --The Character added event returns a object value, being the character.
        char:FindFirstChild('Humanoid').Name = 'PlayerControl' --This I heard will disable the ROBLOX resetting. So if you want an anti reset script, this is it.
    end)
end)
Ad
Log in to vote
1
Answered by 8 years ago

Well, first I'm gonna say, that was some interesting grammar, and it took me a while to figure it out, but I think I know where you're going.

You want to wait until a character is fully loaded before moving on to the script. This is quite simple to do. Basically all you need to do is add a repeat function; make sure that this is a localscript, inside any local folder such as StarterGuior StarterPack

this code will also go on the VERY TOP of the script

repeat wait() until game.Players.LocalPlayer.Character

print("Character has loaded")

--do stuff--

Basically the first line yields the script from going on until the character is no longer nil. Once the character has loaded, your script will continue! Once again make sure this is a localscriptinside any local element like StarterGuior StarterPack

Hope this helps!

Answer this question