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

how do I make the script wait for the character to load? [Still Unanswered] [closed]

Asked by
Prioxis 673 Moderation Voter
10 years ago

I'm making a spells script and in play solo of course the player loads before anything else unlike on a actual roblox server the scripts load before the character so when I go to play online my script doesn't work

I tried using player.CharacterAdded:wait() but It doesn't work i'm not even sure if its supposed to be used for this issue ]

heres my script :

01local player = game.Players.LocalPlayer
02local Player = game.Players.LocalPlayer
03local Mouse = player:GetMouse()
04player.CharacterAdded:wait()
05RightShoulder = Player.Character.Torso["Right Shoulder"]
06Run = game:getService("RunService")
07Mouse.KeyDown:connect(function(key)
08    if script.Wait.Value == false then
09if key == "f" then
10    script.Wait.Value = true
11    for i = 1, 2 do
12            for i = 1, 12 do
13                RightShoulder.C0 = RightShoulder.C0 *CFrame.Angles(0, 0, 0.16)
14                RightShoulder.C0 = RightShoulder.C0 *CFrame.Angles(0, 0, 0)
15                Run.Stepped:wait(0.01)
View all 50 lines...
0
Uh, why you defines 2 LocalPlayers in the script...? Xapelize 2658 — 5y
0
game:IsLoaded thenormalelevator32 26 — 5y
0
im a noob scripter but i think you could try game.Players.WaitForChild("Player") coolmanHDMI 72 — 5y
0
bruh this is from 5 years ago why would he reply? Nistrict 44 — 5y
0
lol User#34743 0 — 5y

Closed as Primarily Opinion-Based by youtubemasterWOW, zblox164, and JesseSong

This question has been closed because it is a discussion about a topic focused on diverse opinions, which isn't a good fit for our Q&A format.

Why was this question closed?

20 answers

Log in to vote
2
Answered by 10 years ago
1local Player = game:GetService'Players'.LocalPlayer
2local character = Player.Character or Player.CharacterAdded:wait() -- in case the character model has already been created
3local torso = character:WaitForChild'Torso'
4local rightShoulder = torso:WaitForChild'Right Shoulder'
5local head = character:WaitForChild'Head'

:WaitForChild(string childName) is your friend :P

0
still doens't work Prioxis 673 — 10y
0
thanks dude MicroStud -6 — 6y
0
:WaitForChild() Should do the trick! Crazycreeperdoctor -5 — 5y
Ad
Log in to vote
2
Answered by 6 years ago
1local player = game.Players.LocalPlayer
2 
3repeat
4wait()
5until player.Character:FindFirstChild("Torso")

My method.

Log in to vote
1
Answered by 8 years ago
Edited 8 years ago

I don't know if you still don't know the answer, but there's something called HasAppearanceLoaded that seems to work. Here's an example of it:

01game.Players.PlayerAdded:connect(function(player)
02    player.CharacterAdded:connect(function(char)
03        while player:HasAppearanceLoaded() == false do
04            wait()
05        end
06 
07        local C = char:GetChildren()
08 
09        for i = 1, #C do
10            if C[i]:IsA("Hat") or C[i]:IsA("Accessory") then
11                C[i]:Destroy()
12            end
13            wait(0.001)
14        end
15 
View all 21 lines...
Log in to vote
1
Answered by 6 years ago

This is how I just did it and it worked.

1local Player = game.Players.LocalPlayer
2local Character = Player.Character or Player.CharacterAdded:Wait()
Log in to vote
0
Answered by 10 years ago
1player:WaitForCharacter()
0
where do I put this in the script? Prioxis 673 — 10y
0
now I get an error saying 22:57:45.043 - WaitForCharacter is not a valid member of Player 22:57:45.045 - Script 'Players.Player1.Backpack.Spells', Line 2 Prioxis 673 — 10y
0
Hm. Try player:WaitForChild("Character"), I think WaitForCharacter isn't a thing. I'm tired and confused myself, sorry! SlickPwner 534 — 10y
0
still doesn't work and now it doesn't even work in play solo Prioxis 673 — 10y
2
Try repeat wait() until player:FindFirstChild("Character") SlickPwner 534 — 10y
Log in to vote
0
Answered by 10 years ago

LocalScript, obviously

1local player = game.Players.LocalPlayer
2local character = player:WaitForChild("Character")
3
character isnt a child of player Pumpk1n52 22 — 7y
Log in to vote
0
Answered by
shokobata -15
7 years ago

Man CharacterLoaded fires when the character is loaded

Log in to vote
0
Answered by 7 years ago
1local plr = game.Players.LocalPlayer
2repeat wait() until plr.Character
3local char = plr.Character

This is usually how I go about waiting for the character to load.

Log in to vote
0
Answered by
AltNature 169
5 years ago

GetCharacterFromPlayer()

Log in to vote
0
Answered by 5 years ago
1local Player = game.Players.LocalPlayer
2repeat wait() until Player.Character
Log in to vote
0
Answered by 5 years ago

Using TypeScript

01function onPlayerAdded(player: Player) {
02    player.CharacterAdded.Connect((character) => {
03        while(!player.HasAppearanceLoaded()) {
04            wait();
05        }
06    // do something here...
07    })   
08}
09 
10Players.PlayerAdded.Connect(player => {
11        onPlayerAdded(player);
12    }
13);
14 
15Players.GetPlayers().forEach(player => {
16    onPlayerAdded(player);
17});
Log in to vote
0
Answered by
pingsock 111
5 years ago

I think I've figured it out.

Using the workspace, you can check if the model is the playername, and if it is, it will print a success message.

1game.Players.PlayerAdded:Connect(function(Player)
2    workspace.ChildAdded:Connect(function(Child)
3        if Child.Name == Player.Name then
4            print('Character has loaded.')
5        end
6    end)
7end)
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

It seems like you got a lot of answers already, but simply if I was waiting for a player to load, just use an approximate guess on how long it will take and then use that as a wait().

Log in to vote
0
Answered by 5 years ago

Maybe change the Cframes to parent the player

Log in to vote
0
Answered by 5 years ago

I like doing this:

1local Character = player.Character or player.CharacterAdded:Wait()
Log in to vote
0
Answered by
TickoGrey 116
5 years ago

before your script starts just put this in:

1game:GetService("Players").PlayerAdded:Connect(function(plr)
2game.Workspace:WaitForChild(plr.Name)
3end)

if it does not work please tell me

Log in to vote
0
Answered by 5 years ago

Insert a local script, in the StarterPlayer, in StarterPlayerScripts and write the following

1local Player = game.Players.LocalPlayer
2repeat wait() until Player:GetCharacterFromPlayer(char)
3 
4-------------------------------------------------------------------------
5 
6char:FindFirstChild("Humanoid")
7char.Humanoid.WalkSpeed = 50

You can also add a parameter so you can make more code. SIDENOTE: It's easier to get the character in a local script, than in a normal script

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

I'd do this. It'll work for server (regular) scripts:

1local Players = game:GetService("Players")
2 
3Players.PlayerAdded:Connect(function(player)
4    repeat
5        wait()
6    until
7    player.Character ~= nil
8end)
Log in to vote
0
Answered by
Nckripted 580 Moderation Voter
5 years ago
1local char = player.CharacterAdded:Wait(5)

Hope this helps!

0
this is a 5 year old question. ScriptsALot 91 — 5y
Log in to vote
-1
Answered by
GShocked 150
8 years ago

If you want it to wait for your physical character this will work in a local script:

1game.Workspace:WaitForChild(game.Players.LocalPlayer.Name)
0
HOW DID U GET 2 UPVOTES............. Do you not realize if the players name is a part in the game, you could destroy the player... greatneil80 2647 — 6y