So I have a Tornado Survival game, and have a feature where if you are in the map surviving, you are gaining a leaderstat point every second. This is done with a large Part named 'gain' that covers the whole map, and the script is placed inside of it. The main problem I have is that the script has it only apply to one player at a time, so if me and my friends play, I am the only one gaining points.
So I was wondering if anybody knew how to check if multiple people are colliding with a Part, and how that script would look? Thanks!
local waittime = 1
local debounce = true
-- This debounce variable prevents the script from spamming points
function OnTouched(hit)
if hit and hit.Parent and debounce then
-- Make sure hit is isn't nil and debounce is ready
debounce = false
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
-- Get the player from whatever bodypart hit the brick.
if player then
-- Make sure a player hit the brick
local leaderstats = player:FindFirstChild("leaderstats")
-- Make sure they have the leaderstats Value.
local level = leaderstats and leaderstats:FindFirstChild("Money")
-- Make sure they have the level Value in leaderstats.
if level then
level.Value = level.Value + 1
wait(waittime)
end
end
debounce = true
end
end
script.Parent.Touched:Connect(OnTouched)

2 comments
I have one problem with that, when I use that script, once 1 player dies, nobody else is gaining points.
@puppyfriend edited answer