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

Why does my player variable not work?

Hello. I am making this tagging game where there are safe areas. I am making a variable for each player called invincibility. Please do not tell me to do this with a different method because I just wanna use this method and this method is very important. Why does my code not work?

local Players = game:GetService("Players")
game.Players.PlayerAdded:Connect(function(player)
    local invincibility = Instance.new("BoolValue")
    invincibility.Name="invincibility"
    invincibility.Value=false
    invincibility.Parent=player
    local PlayerCount = #Players:GetPlayers()
    local it
    if PlayerCount==1 then
        it=player
        print(player.Name .. " is it!")
        player.invincibility=true
    end
end)

Output:

  betweenplacements is it!
  10:35:04.122 - invincibility is not a valid member of Player
10:35:04.124 - Stack Begin
10:35:04.124 - Script 'Workspace.Script', Line 12
10:35:04.124 - Stack End

1 comment

0

In that script, you could just use the already provided invincibility.Value, but otherwise you need to specify that you want to change the value.

1 answer

✓ Accepted answer

hi u forgot the value at line 12 brrrrrrrrrr

local Players = game:GetService("Players")
game.Players.PlayerAdded:Connect(function(player)
    local invincibility = Instance.new("BoolValue")
    invincibility.Name="invincibility"
    invincibility.Value=false
    invincibility.Parent=player
    local PlayerCount = #Players:GetPlayers()
    local it
    if PlayerCount==1 then
        it=player
        print(player.Name .. " is it!")
        player.invincibility.Value=true
    end
end)

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