Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

how to fix system message on part touch getting multiplied?

Asked by 3 years ago

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)

2 answers

Log in to vote
1
Answered by 3 years ago

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)

0
your right, also table.insert does not take the index anymore in the second parameter, so you only need the table and the value Xapelize 2658 — 3y
0
evaera also should learn from you because she don't know how to make debounce on the comments Xapelize 2658 — 3y
0
noob yapelize this guy is pro, `table.find` does linear search, player that touched the part is very likely to be the first one to touch it again 5 times in a row cuz every limb, this guy inserts the player at start of table so `table.find` will find the player immediately imKirda 4491 — 3y
0
what no i though table.insert second parameter died Xapelize 2658 — 3y
Ad
Log in to vote
1
Answered by
Antelear 185
3 years ago
Edited by imKirda 3 years ago

have you tried debounce? https://www.youtube.com/watch?v=-brqROQI-8w -- tutorial on debounce

Answer this question