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

How to store a value for each player when they join?

Asked by 6 years ago

I am making a game in which players must escape from a monster, and I thought adding a boolvalue for each player to tell whether they have escaped or not would be a good idea.

However, I cannot figure out how to add the value to the folder when they join.

This is the code I have:

local player = game.Players:GetPlayers()
local EscapeValue = Instance.new("BoolValue")
EscapeValue.Name = player.Name
EscapeValue.Parent = game.ServerStorage.PlayerEscaped
EscapeValue.Value = false

Any help is appreciated.

1 answer

Log in to vote
0
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
6 years ago

Just store the names of the players in a table

local whoEscaped = {}

--when someone escapes:
whoEscaped[plr.Name] = true

--when someone unescapes or something:
whoEscaped[plr.Name] = nil

--when you need to check if they escaped:
if whoEscaped[plr.Name] then
    print("escaped")
else
    print("didn't escape")
end

--also make sure to remove them from the table when they leave the game:
game:GetService("Players").PlayerRemoving:Connect(function(plr)
    whoEscaped[plr.Name] = nil
end)
0
Thank you, this worked. Ramshackles 14 — 6y
Ad

Answer this question