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

how would i reference the player?

Asked by
emervise 123
4 years ago
01game.Players.PlayerAdded:Connect(function(player)
02        print(player.name "joined")
03        if not player.Character then
04        print("waiting for character")
05        player.CharacterAdded:wait();
06        char = player.Character
07    else
08        char = player.Character
09    end
10end)
11local hum = char.humanoid
12hum.died:Connect(function()
13    player:kick()
14end)
15game.Players.PlayerAdded:Connect(function(player)
16    player:kick()
17end)
0
I am getting two errors; ServerScriptService.Script:11: attempt to index nil with 'humanoid' and ServerScriptService.Script:2: attempt to call a string value emervise 123 — 4y
0
Let me mess around with it and see what I can do.. Configuator 158 — 4y

1 answer

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

to get humanoid you should do this >

1local hum = char:WaitForChild("Humanoid") -- waits until Humanoid appears and won't be a nil value, also its "Humanoid" with capital H

to fix line 2 you should do this >

1print(player.name.. " joined") -- ".." connects 2 strings

fixed script :

01game.Players.PlayerAdded:Connect(function(player)
02        print(player.name.. " joined")
03        if not player.Character then
04        print("waiting for character")
05        player.CharacterAdded:wait();
06        char = player.Character
07    else
08        char = player.Character
09    end
10end)
11local hum = char:WaitForChild("Humanoid")
12hum.Died:Connect(function()
13    player:kick()
14end)
15game.Players.PlayerAdded:Connect(function(player)
16    player:kick()
17end)
0
ServerScriptService.Script:11: attempt to index nil with 'WaitForChild' this is the error I get. emervise 123 — 4y
0
make sure that you typed "char:WaitForChild" not "char.WaitForChild", don't use "." and use ":" SuAkihiro 94 — 4y
0
Use player.Name instead of player.name JesseSong 3916 — 4y
0
I used : emervise 123 — 4y
Ad

Answer this question