How do I make this not global and be for every player individually?
local Time = 300
local db = 0
local timedisplay = script.Parent.Timer.TextLabel
script.Parent.Touched:Connect(function(hit)
if db == 0 then
if hit.Parent:FindFirstChild("Humanoid") then
task.spawn(function()
db = Time
for i = 1, Time do
task.wait(1)
db -= 1
timedisplay.Text = tostring(db)
end
end)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
plr.leaderstats.Gold.Value = plr.leaderstats.Gold.Value + 50
end
end
end)
local Time = 300
local Activated = false
local db = 0
local timedisplay = script.Parent.Timer.TextLabel
script.Parent.Touched:Connect(function(hit)
if not Activated then
Activated = true
if db == 0 then
if hit.Parent:FindFirstChild("Humanoid") then
task.spawn(function()
db = Time
for i = 1, Time do
task.wait(1)
db -= 1
timedisplay.Text = tostring(db)
end
end)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
plr.leaderstats.Gold.Value = plr.leaderstats.Gold.Value + 50
end
end
wait(2) -- Delay
Activated = false
end
end)
Please do not listen to other replies in this section. They are either recommending you to use localscripts for leaderstats (garbage) or using “global” debounces.
You should use these debounces:
local debounces = {}
function Do(userId)
if debounces[userId] == true then return end
debounces[userId] = true
--Code here
debounces[userId] = false
end
This is a basic demonstration, if you want to use time your debounce code should vary.
I can also see that you are trying to update textlabels, use remoteevents for this
they’ve never said anything “locally” AFAIK, the topic creator didn’t use the correct words for the topic but by reading the script you can clearly see he’s not attempting to make a leaderstat script “local”