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

why does this not kill the player on join?

Asked by 3 years ago
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.

0
Why do you have 2 different connections to Players.PlayerAdded?? jundell 106 — 3y
0
I think he made a typo, maybe he wanted to put .PlayerRemoving. Sarturex857 109 — 3y

1 answer

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

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 :)

Ad

Answer this question