Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

how would i reference the player?

Asked by 2 months 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 BRO_ITmeYO 106 — 2mo
0
Let me mess around with it and see what I can do.. RareBIue 128 — 2mo

1 answer

Log in to vote
1
Answered by 2 months ago
Edited 2 months 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. BRO_ITmeYO 106 — 2mo
0
make sure that you typed "char:WaitForChild" not "char.WaitForChild", don't use "." and use ":" SuAkihiro 48 — 2mo
0
Use player.Name instead of player.name Jessesong 1430 — 2mo
0
I used : BRO_ITmeYO 106 — 2mo
Ad

Answer this question