If the title didn't make sense, which it most likely didn't, I'll explain it better here.
Background Information: I have a brick that when you touch it, a server script inside it adds a new string value into a folder thats called "GamePlayers". This string value is basically saying, "This player is inside the game." The thing is, when you touch the brick, the specific player can enter more than once (He can have more than 1 string value). Therefore, I need a way to debounce the player to make sure each player can only have 1 string value to their name.
Question: How do I make a debounce to a player's name when hitting a brick. I have the script here that I was working on that didn't work:
local GamePlayers = workspace:FindFirstChild("GamePlayers")
local debounce = false
script.Parent.Touched:Connect(function(hit)
if debounce then return end
debounce = true
if hit.Parent:FindFirstChild("Humanoid") then
if GamePlayers:FindFirstChild("Player") then -- checks if there is even a player inside the folder.
if not GamePlayers.Player.Value == hit.Parent.Name then -- ||MY FAILED PLAYER DEBOUNCE|| --
GamePlayers.Player.Value[hit.Parent.Name] = true -- My failed debounce again
local NewPlayer = Instance.new("StringVal")
NewPlayer.Parent = GamePlayers
NewPlayer.Name = "Player"--All players values are named Player so the thing can check if there is a stringval with the value of their name.
NewPlayer.Value = hit.Parent.Name
else
GamePlayers.Player.Value[hit.Parent.Name] = true -- My failed debounce again
local NewPlayer = Instance.new("StringVal")
NewPlayer.Parent = GamePlayers
NewPlayer.Name = "Player"--All players values are named Player so the thing can check if there is a stringval with the value of their name.
NewPlayer.Value = hit.Parent.Name
end
end
wait(0.5)
debounce = false
GamePlayers.Player.Value[hit.Parent.Name] = false -- My failed debounce ONCE AGAIN
end)
