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

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

Asked by 6 years ago
Edited 6 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
1
Answered by 6 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.

script.Parent.Touched:connect(function(part)
    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
        end
    end
end)

I hope this solves your problem!

Ad
Log in to vote
0
Answered by 6 years ago

Complementing the --Code here part from TDaGreat:

player.Backpack.CreditCard.Destroy()
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