Hey! So I’m making a “Winner” part which basically prints a players name if they touch the part. I don’t want to take any credit or anything but the script was made by MarkiPr0឵8 who helped me fix a previous issue which the script had.
Anyways, here is the script:
local Players = game:GetService("Players")
local WinnerCoin = game.ReplicatedStorage:WaitForChild("WinnerCoin")
local Names = {}
local Part = script.Parent
Part.Touched:Connect(function(Hit)
if not Hit.Parent:FindFirstChildWhichIsA("Humanoid") then return end
Names[#Names+1] = Hit.Parent.Name
WinnerCoin.Value = ("Winners: "..(table.concat(Names, ", ")))
end)
What I want to achieve is that when a player touches it, I just want it to print the players name just once, I tried debounce but that isn’t really efficient. Also have heard to store the usernames in a string boolean dictionary but I’m not that familiar with that.
local Players = game:GetService("Players")
local WinnerCoin = game.ReplicatedStorage:WaitForChild("WinnerCoin")
local Names = {}
local Part = script.Parent
local foundPlayer = false -- boolean which tells if we found the same player
Part.Touched:Connect(function(Hit)
if not Hit.Parent:FindFirstChildWhichIsA("Humanoid") then return end
for i,v in ipairs(Names) do
if v == Hit.Parent.Name then foundPlayer = true break end
end
if not foundPlayer then
Names[#Names+1] = Hit.Parent.Name
WinnerCoin.Value = ("Winners: "..(table.concat(Names, ", ")))
end
foundPlayer = false
end)