I have win part ontouch but the problem is If I don’t make the wait() lower than .1 the player keeps getting extra wins.
if i put wait(1) the players doesn’t get extra wins. but when I do that the other players have to wait 1 second before they get theirs. can i add the debounce on the local script or something? Any solutions will help.
Part script:
local db = true
local remote = game.ReplicatedStorage.XPGIVE
script.Parent.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr and db then
db = false
plr.leaderstats.Wins.Value += 1
plr.leaderboard.Exp.Value += 50
remote:FireClient(plr, script.Parent)
wait(0.1) -- If I make this higher other players can't get it in time
db = true
end
end)
local touched = {}
--function fired
if table.find(touched,player) then
table.insert(touched,player)
--what code you want it to run
wait(1)
table.remove(touched,player)
end
local db = {}
local replicated = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local remote = replicated.XPGIVE
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") == nil then return end
local plr = Players:GetPlayerFromCharacter(hit.Parent)
if not db[plr.Name] then
db[plr.Name] = true
plr.leaderstats.Wins.Value += 1
plr.leaderboard.Exp.Value += 50
remote:FireClient(plr, script.Parent)
task.wait(0.1)
db[plr.Name] = nil
end
end)
local replicated = game:GetService("ReplicatedStorage")
local remote = replicated:WaitForChild("XPGIVE")
remote.OnClientEvent:Connect(function(part)
part:Destroy()
end)