Hey, do you guys know why it fires multiple times to the server? I tried to use debounce like someone told me but it still not working correctly. When I test the game alone and collect all the parts it works and the value is correct but when I play test with more than 1 people when I collect a part it adds more than just 1 , for example it could add like 6 on the value if u collect just one part. Any ideas on why this might be happening?
local milktext = gui:WaitForChild("MilkCountFrame"):WaitForChild("MilkAmount") local dialogue = gui:WaitForChild("DialogueFrame") local currentmilk = game:GetService("ReplicatedStorage"):WaitForChild("CurrentMilk") local totalmilk = 0 local debounce = false for _,Part in ipairs(workspace.GameMilks:GetChildren()) do if Part:IsA("BasePart") then Part.Touched:Connect(function(Hit) if not debounce then debounce = true Part:Destroy() print("u got the milk") totalmilk += 1 milktext.Text = totalmilk dialogue.Visible = true dialogue:WaitForChild("TextLabel").Text = "A milk has been obtained." task.wait(1) dialogue.Visible = false currentmilk:FireServer(Hit) end debounce = false end) end end