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

Multiple of the same names are sometimes showing up on my gui. How would I only let one show up?

Asked by 6 years ago
Brick = script.Parent 

Brick.Touched:connect(function(part) 
    if part.Parent.Humanoid then 
        if part.Parent.Humanoid.Health > 0 then 
            wait(0.5)
            part.Parent:MoveTo(game.Workspace.EasyLobby.Position + Vector3.new(0,1,0))
            local plr = game.Players:FindFirstChild(part.Parent.Name)
            game.ReplicatedStorage.Winners.Value = game.ReplicatedStorage.Winners.Value.." "..plr.Name
        end
    end
end)

Hey guys I have a round-based game, and this script is inside of the part, where players touch it, they win

It works fine, but if someone wins, they're name will sometimes be printed more than once. I don't want to add a debounce in time because another player could step on the brick at the same time. Any ideas?

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

This is a simple mistake, what you did was make it to where it adds the players name every single time the player touches it, which is infinite times per second. What you need to do is add

if game.ReplicatedStorage.WinnersValue.Value ~= plr.Name then
    -- add the same script as before and it should work just fine.
end

Hope I helped.

EDIT: The script must only be around changing the value of the WinnersValue, not the whole script.

0
Hey, thanks for this, but there will be multiple winners, and this only works for one person. How would this work? User#19950 0 — 6y
0
If there are multiple winners you could make a folder and when a player touches the brick it inserts a model into that folder with the name of the player (if the player doesn't already have a model in it) and then you make a table with i, v in pairs and put "v.Name" as the name of an Instance.new("Model") cmgtotalyawesome 1418 — 6y
0
I didn't mean to say and then you make a table, I meant to say thats how you would do it cmgtotalyawesome 1418 — 6y
Ad

Answer this question