i have an end part that when touched the system will put a message in chat saying the player finished the game, but when it chat it chats like 50 times, please help ty
part touch script
script.Parent.Touched:Connect(function(part) for i,v in pairs(game.Players:GetPlayers()) do if part:IsDescendantOf(v.Character) then game.ReplicatedStorage.ReachedEnd:FireAllClients(v.Name) end end end)
message creator local script
game.ReplicatedStorage.ReachedEnd.OnClientEvent:Connect(function(plrName) game.StarterGui:SetCore("ChatMakeSystemMessage", { Text = "[Game] " .. plrName .. " Reached the end", Color = Color3.fromRGB(255, 255, 255), Font = Enum.Font.Cartoon, TextSize = 18, }) end)
You can try adding a table for the players who are finished and so if you touch the part, you get added but if touch the part again but already added to the table, it won't send way too many messages.
local finishedplayers = {} script.Parent.Touched:Connect(function(part) for i,v in pairs(game.Players:GetPlayers()) do if part:IsDescendantOf(v.Character) and not table.find(finishedplayers,v) then table.insert(finishedplayers,1,v) game.ReplicatedStorage.ReachedEnd:FireAllClients(v.Name) end end end)
have you tried debounce? https://www.youtube.com/watch?v=-brqROQI-8w -- tutorial on debounce