I’m having an issue where my script counts a “goal” way too many times if I claim a flag. For context, I made a system where if someone messes up and accidentally claims 2 flags, they can unclaim one, and someone else can claim it, or they can reclaim one if they double-click. However, this seems to break my scoring system. For example; say I claimed/clicked the flag twice. So, if I scored a goal, it would count that goal twice (I have videos below to visually demonstrate this). How do I fix this where it only counts the goal as how it’s supposed to be without it detecting the player who clicked too many times?
Hypothetically, say I clicked this 3 times. This is what should happen:
Instead this happens:
Code:
local flag = script.Parent.Parent
local click = script.Parent.ClickDetector
local name = flag.Names.SurfaceGui.TextLabel
local db = false
local taken = false
local Timer = workspace.Timer.Value
local Score = workspace.Flag.SurfaceGui.TextLabel
local Number = script.Parent.Parent.Score.SurfaceGui.TextLabel
click.MouseClick:Connect(function(plr)
if not taken then
flag.Name = " " ..plr.Name
name.Text = " " ..plr.Name
taken = true
else
taken = false
name.Text = "---"
flag.Name = "DisplayFlagName"
end
if flag.Name == "DisplayFlagName" then
db = false
else
db = true
end
if db then
repeat
while wait(0.001) do
local Track = script.Parent.Parent.Score.Value
if Score.Text == "Regular: " ..plr.Name then
Track.Value += 1
print(Track.Value)
Number.Text = Track.Value
if name.Text == "---" then
break
end
end
if Score.Text == "Gold: " ..plr.Name then
Track.Value += 3
print(Track.Value)
Number.Text = Track.Value
if name.Text == "---" then
break
end
end
end
until Timer == 0
end
end)
That’s because of the Roblox hitboxes, since the character is constantly animated, the part that when touched that will give you points, will detect a touch a few times.
To fix that you need to use debounce but I don’t know how to use it.
I’m convinced it’s the amount of times you click on it. It detects the player name multiple times, so it gets confused and counts the score multiple times because the same player has clicked it over and over. In my first video, you can see how evident that is.
local flag = script.Parent.Parent
local click = script.Parent.ClickDetector
local name = flag.Names.SurfaceGui.TextLabel
local db = false
local taken = false
local Timer = workspace.Timer.Value
local Score = workspace.Flag.SurfaceGui.TextLabel
local Number = script.Parent.Parent.Score.SurfaceGui.TextLabel
click.MouseClick:Connect(function(plr)
if not taken then
flag.Name = " " ..plr.Name
name.Text = " " ..plr.Name
taken = true
else
taken = false
name.Text = "---"
flag.Name = "DisplayFlagName"
end
if flag.Name == "DisplayFlagName" then
db = false
return
else
db = true
end
if db then
repeat
while wait(0.001) do
local Track = script.Parent.Parent.Score.Value
if Score.Text == "Regular: " ..plr.Name then
Track.Value += 1
print(Track.Value)
Number.Text = Track.Value
if name.Text == "---" then
break
end
end
if Score.Text == "Gold: " ..plr.Name then
Track.Value += 3
print(Track.Value)
Number.Text = Track.Value
if name.Text == "---" then
break
end
end
end
until Timer == 0 or name.Text == "---"
end
end)
I figured out the solution, it’s actually pretty complicated but it seems like I just needed to return the script if there was no name.
local flag = script.Parent.Parent
local click = script.Parent.ClickDetector
local name = flag.Names.SurfaceGui.TextLabel
local db = false
local taken = false
local Timer = workspace.Timer.Value
local Score = workspace.Flag.SurfaceGui.TextLabel
local Number = script.Parent.Parent.Score.SurfaceGui.TextLabel
click.MouseClick:Connect(function(plr)
if not taken then
flag.Name = " " ..plr.Name
name.Text = " " ..plr.Name
taken = true
else
taken = false
name.Text = "---"
flag.Name = "DisplayFlagName"
end
if flag.Name == "DisplayFlagName" then
db = false
else
db = true
end
if taken then
while wait(0.1) do
if Timer.Value < 300 then
click.MaxActivationDistance = 0
break
end
if not taken then
return
end
end
repeat
while wait(0.001) do
local Track = script.Parent.Parent.Score.Value
if Score.Text == "Regular: " ..plr.Name then
Track.Value += 1
print(Track.Value)
Number.Text = Track.Value
end
if Score.Text == "Gold: " ..plr.Name then
Track.Value += 3
print(Track.Value)
Number.Text = Track.Value
end
end
until Timer.Value == 0
end
end)