Still have questions? Join our Discord server and get real time help.
Log in to vote

Finding a players name to edit the properties inside of it?

Asked by 2 years ago
Edited 2 years ago

I am busy making a roblox game and wanted to make a game that will remove a item from the players inventory and add some cash for it.....

My game is SO FAR robbing a bank but there is a part in which you can collect credit cards and put it into a ATM for cash....So basically I want for someone to pick up a card bring it to the ATM and insert it inside...Once they have done that it must remove their card from their inventory and add 1000$ to their account.


MAIN PROBLEM: I know how to make clickable items to start a script for them to insert the card but I don't understand how to edit their properties because I do not have their name so I need to find how to get their name is find it in my PLAYERS properties.


2 answers

Log in to vote
Answered by 2 years ago

This seems like a good time to use GetPlayerFromCharacter! GetPlayerFromCharacter is a function of Players. It has one argument. In that argument you put the character you want to get the player from, and than it returns the player that owns that character.

For example:

local player = game.Players:GetPlayerFromCharacter(game.Workspace.Player1)

Here is one that is more fitting to your situation.

    if part.Name == "Credit Card" then -- Check to see if the part is credit card
        if part.Parent.Parent:FindFirstChild("Humanoid") then -- See if a player is holding the credit card 
            local player = game.Players:GetPlayerFromCharacter(part.Parent.Parent) -- Get the player from the charecter
            -- Your code here

I hope this solves your problem!

Log in to vote
Answered by 2 years ago

Complementing the --Code here part from TDaGreat:

player.leaderstats.Money.Value = Money.Value + 1000 --Change 1000 to whatever money you want to give

Since you havent give a name for the Money i assumed it was an IntValue in a folder named "leaderstats" inside the player.

Answer this question