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
1 | script.Parent.Touched:Connect( function (part) |
2 | for i,v in pairs (game.Players:GetPlayers()) do |
3 | if part:IsDescendantOf(v.Character) then |
4 | game.ReplicatedStorage.ReachedEnd:FireAllClients(v.Name) |
5 | end |
6 | end |
7 | end ) |
message creator local script
1 | game.ReplicatedStorage.ReachedEnd.OnClientEvent:Connect( function (plrName) |
2 |
3 | game.StarterGui:SetCore( "ChatMakeSystemMessage" , { |
4 | Text = "[Game] " .. plrName .. " Reached the end" , |
5 | Color = Color 3. fromRGB( 255 , 255 , 255 ), |
6 | Font = Enum.Font.Cartoon, |
7 | TextSize = 18 , |
8 | } ) |
9 | 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.
1 | local finishedplayers = { } |
2 | script.Parent.Touched:Connect( function (part) |
3 | for i,v in pairs (game.Players:GetPlayers()) do |
4 | if part:IsDescendantOf(v.Character) and not table.find(finishedplayers,v) then |
5 | table.insert(finishedplayers, 1 ,v) |
6 | game.ReplicatedStorage.ReachedEnd:FireAllClients(v.Name) |
7 | end |
8 | end |
9 | end ) |
have you tried debounce? https://www.youtube.com/watch?v=-brqROQI-8w -- tutorial on debounce