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
3 years ago
game.Players.PlayerAdded:Connect(function(player)
        print(player.name "joined")
        if not player.Character then
        print("waiting for character")
        player.CharacterAdded:wait();
        char = player.Character
    else
        char = player.Character
    end
end)
local hum = char.humanoid
hum.died:Connect(function()
    player:kick()
end)
game.Players.PlayerAdded:Connect(function(player)
    player:kick()
end)

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 — 3y
0
Let me mess around with it and see what I can do.. Configuator 158 — 3y

1 answer

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

to get humanoid you should do this >

local 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 >

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

fixed script :

game.Players.PlayerAdded:Connect(function(player)
        print(player.name.. " joined")
        if not player.Character then
        print("waiting for character")
        player.CharacterAdded:wait();
        char = player.Character
    else
        char = player.Character
    end
end)
local hum = char:WaitForChild("Humanoid")
hum.Died:Connect(function()
    player:kick()
end)
game.Players.PlayerAdded:Connect(function(player)
    player:kick()
end)

0
ServerScriptService.Script:11: attempt to index nil with 'WaitForChild' this is the error I get. emervise 123 — 3y
0
make sure that you typed "char:WaitForChild" not "char.WaitForChild", don't use "." and use ":" SuAkihiro 94 — 3y
0
Use player.Name instead of player.name JesseSong 3916 — 3y
0
I used : emervise 123 — 3y
Ad

Answer this question