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

How to get a specific player from the online players?

Asked by 4 years ago

Hey, I'm very new to coding and I want to make a script, where on a press of a button a specific player's integer value will change, here's the script I made:

script.Parent.MouseButton1Up:Connect(function(player)
    local setCashButton = script.Parent
    local playerName = script.Parent.Parent.playerNameTxtBox.Text
    local cashValue = script.Parent.Parent.cashValueTxtBox.Text
    local playerLoc = game.Players.playerName

    playerLoc.leaderstats.Cash.Value = cashValue
end)

The problem with this, is that I can't figure out how to search for a specific player that is in the server, the code fails at line 5 when I try to specify the given player's name. Any help would be appreciated!

0
You pass in a "player" parameter, I assume that this is a reference to the current player in Players. But if this is a localscript (considering you're taking inputs), leaderstats should only be tampered with by the server in most if not all cases. Use a remoteevent and impose the appropriate checks, I can't tell what'd they be from this script alone. desperateforthelols 35 — 4y
0
Well this sound very complicated. Any recommendations on how to start this? Playsourus 0 — 4y
0
yes, read api about RemoteEvents Leamir 3138 — 4y
0
also, you can use `[variable]` to include variables values, you may need to use that on line 5 Leamir 3138 — 4y
0
Will do it tomorrow, it's getting late. Thanks for the help! Playsourus 0 — 4y

1 answer

Log in to vote
-1
Answered by 4 years ago
Edited by Leamir 4 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.

So what you need to do is:

script.Parent.MouseButton1Up:Connect(function(player)
        local setCashButton = script.Parent
        local playerName = script.Parent.Parent.playerNameTxtBox.Text
        local cashValue = script.Parent.Parent.cashValueTxtBox.Text
        local playerLoc = player.Name

        playerLoc.leaderstats.Cash.Value = cashValue
    end)
0
Hey! Thanks for the reply but unfortunately I am still getting an error at line 5 ( 14:34:00.044 - Players.Playsourus.PlayerGui.adminMenu.adminGUI.adminFrame.setCash.setCash.LocalScript:5: attempt to index number with 'Name' 14:34:00.045 - Stack Begin 14:34:00.046 - Script 'Players.Playsourus.PlayerGui.adminMenu.adminGUI.adminFrame.setCash.setCash.LocalScript', Line 5 14:34:00.046 - Stack End) Playsourus 0 — 4y
0
i see.. So the problem is line 3 "local playerName = script.Parent.Parent.playerNameTxtBox.Text" cause you have written " local playerLoc = game.Players.playerName" So Fix that and it will work :) ninjabluekris -4 — 4y
0
Hey, made the changes, but if I understand the output correctly, the script is searching for a player named playerName not the string that the variable has. ( 14:48:54.997 - playerName is not a valid member of Players 14:48:54.997 - Stack Begin 14:48:54.997 - Script 'Players.Playsourus.PlayerGui.adminMenu.adminGUI.adminFrame.setCash.setCash.setCashScript', Line 5 14:48:54.997 - Stack End) Playsourus 0 — 4y
Ad

Answer this question