Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

how do I get the string value of the player?

I'm trying to make a variable for the players cash stat. The players cash stat is located in a folder inside ServerStorage. the cash stat is named whatever the players username is. is there anyway I could make the "player" variable a string so I could use it to get the players cash stat?

this is the error I'm getting. "player is not a valid member of Folder"

giver.Touched:connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	local cash = game.ServerStorage.PlayerMoney.player

1 answer

✓ Accepted answer

You are trying to access the values using a player object - that's not possible. The other issue is that you are trying to index a value in the PlayerMoney named player, and it doesn't exist.

Here's the fixed code.

giver.Touched:connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    local cash = game.ServerStorage.PlayerMoney[player.Name]

[string] is special because it allows you to find children using a string instead of a fixed value (like .player).

1 comment

0

ah ok thank you. I tried player.Name just without the brackets.

This discussion is preserved as it was. New answers, comments, and votes are closed.