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

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

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

✓ Accepted answer

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)

1 comment

0

Thank you, this worked.

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