I have this obstacle course demo. It spawns a map, the player completes it and touches a win block. This block is meant to increment the number of wins the player has. However, it goes off more than once when the player initiates contact with the block. I have attempted to create a table to store past winners to avoid this, but it will not work.
local beenAwarded = {} --used to store winner names (those who touched the block)
script.Parent.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local character = hit.Parent.Humanoid
print "human found"
local plrname = hit.Parent.Name
local plr = game.Players:FindFirstChild(plrname)
if plr then
local stats = plr:FindFirstChild("leaderstats")
if stats then
wait(.1)
plr.Character.HumanoidRootPart.CFrame = CFrame.new(game.Workspace.SpawnLocation.Position)
if beenAwarded[plr] then return end -- if the player has been added to the table it ends the function
table.insert(beenAwarded, plr) -- otherwise the player is added here (i have tried the same thing using the player name, same result)
local wins = stats.Wins
wins.Value = wins.Value + 1
end
end
end
end)

2 comments
what do you mean make the event a variable? & i can't use a debouce because the delay before the touch can be used again is not something i can have
Why not just use a debounce?