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

Is it posible to specify a value with player.Name and code the code to check for username in value??

Asked by 1 year ago

Hi, is it possible to code it so that the code can check the value of a string value using player.Name in the code? Not player.Name in the value, but having a players username in value and using player.Name to specify a part if there are a lot of players? I know this is a weird question and hopefully I explained my question right.

0
So is it like you have a value, that is the same as the players name? Jay123abc2 241 — 1y
0
yes. theking66hayday 841 — 1y

1 answer

Log in to vote
1
Answered by 1 year ago

Here is the code you are needing:

local ValueStorage = game.ServerStorage.PlayerValues -- this is were the values are stored, change this to were they are.

local Player = PlayerHere -- This is not needed if in a function such as playeradded that returns the player.

local Value = ValueStorage:FindFirstChild(Player.Name) -- Gets the value from the players name
print(Value.Value) -- prints the value.

ValueStorage is where all the values are parented to, in this example it's a folder called PlayerValues in serverStorage. It then states what the player is. It then will find the first value with the players name, and set it to Value. Finally, it will print the value off that.

If the value off a value is a players name, such as a value named "PlayerName" having a value off the name, the code will be this:

local ValueStorage = game.ServerStorage.PlayerValues -- this is were the values are stored, change this to were they are.

local Player = PlayerHere -- This is not needed if in a function such as playeradded that returns the player.

local value -- sets this as the value later in the code.

for i, Value in pairs(ValueStorage:GetChildren()) do
    if Value.Value == Player.Name then
        value = Value
        break
    end
end

This will simply loop through every value until it gets the one it wants. It then sets the local value to it.

0
Thank you for explaining it this helps me a lot theking66hayday 841 — 1y
Ad

Answer this question