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

How to match up a players name with a string name?

Asked by
zomspi 541 Moderation Voter
4 years ago

I am new to i, v loops and am not sure how I would match up a string (a) to a players name?

game.ReplicatedStorage.Common.OnServerEvent:Connect(function(player, a)
    if player.leaderstats.Credits.Value >= 100 then
        player.leadersats.Credits.Value = player.leaderstats.Credits.Value - 100
        local plrs = game.Players:GetChildren()
        for i, v in pairs(plrs) do
            if a == plrs.Name then
            local a = -- That player
            end
        end
    end
end)
0
What's the a variable supposed to be? niroqeo 123 — 4y
0
You don't really need a for loop. You can just do, if game.Players:FindFirstChild(a) then local newPlayer = a end killerbrenden 1537 — 4y

2 answers

Log in to vote
0
Answered by
CjayPlyz 643 Moderation Voter
4 years ago
Edited 4 years ago

Try this:

game.ReplicatedStorage.Common.OnServerEvent:Connect(function(originalplayer, a)
    local credits = originalplayer.leaderstats.Credits
    if credits.Value >= 100 then
            credits.Value = credits.Value - 100
    end

    for i, player in pairs(game.Players:GetChildren()) do
        if a == player.Name then
            local a = player
        end
    end
end)

the answer might change depending on what "a" is

0
bro HappyTimIsHim 652 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

ummmm im not sure what ur asking but when u detect the remote event there's a parameter called player and thats the player and if ur wanting the name just do player.Name

Answer this question