Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

how would i reference the player?

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)

2 comments

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

0

Let me mess around with it and see what I can do..

1 answer

✓ Accepted answer

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)

4 comments

0

ServerScriptService.Script:11: attempt to index nil with 'WaitForChild' this is the error I get.

0

make sure that you typed "char:WaitForChild" not "char.WaitForChild", don't use "." and use ":"

0

Use player.Name instead of player.name

0

I used :

This discussion is preserved as it was. New answers, comments, and votes are closed.