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

why does this not kill the player on join?

local FirstTime = {}



game.Players.PlayerAdded:Connect(function(Player)
	
	
	
	Player.CharacterAdded:Connect(function(Character)
		if FirstTime[Player.UserId] == nil then
			FirstTime[Player.UserId] = true
			Player.Character.Humanoid.Health = 0

		end
		
		
	end)
	
	

end)

game.Players.PlayerAdded:Connect(function(Player)
	FirstTime[Player.UserId] = nil
end)

this code basically sets the players health to 0 but for some reason humanoid does not die and health goes up.

2 comments

0

Why do you have 2 different connections to Players.PlayerAdded??

0

I think he made a typo, maybe he wanted to put .PlayerRemoving.

1 answer

You should use:

repeat task.wait() until plr.Character -- plr is the player instance value

To check if 'Character' is a children of Player.

Also if you want to check if the player just joined, instead of using a dictionary/array, you can give the player a BoolValue.

To use it like this.

local FirstTime = {}

game.Players.PlayerAdded:Connect(function(Player)
    local folder = Instance.new('Folder')
    folder.Parent = Player
    folder.Name = 'PlrValues' -- you can change this to whatever you want.

    local FirstTime = Instance.new('BoolValue')
    FirstTime.Parent = folder
    FirstTime.Name = 'FirstTimeBool' -- you can change this to whatever you want too.
    FirstTime.Value = false

    Player.CharacterAdded:Connect(function(Character)
        repeat task.wait() until plr.Character

        if FirstTime.Value == false then
            FirstTime.Value = true
            Player.Character.Humanoid.Health = 0
        end
    end)
end)

You will not need the event PlayerRemoving, because if the player joins again the server, the value 'FirstTImeBool' will be false(Unless you save it in a datastore).

Hope this helped :)

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