How to adress game.players."player name that script found".leaderstats

I need to find value inside the player with only his name
It sound like very easy issue but i dont know the solutions

Error:
playername is not a valid member of Players “Players” - Server - MakeOwner:19

local players = game:GetService("Players")
local button = script.Parent
local playerv = script.Parent.Value
local sellpart = script.Parent.Parent.Conveyor.Sell
local ownerset = 0

button.Touched:Connect(function(hit)
	if hit.Name == "RightLowerLeg" and ownerset == 0 then
		local player = players:GetPlayerFromCharacter(hit.Parent)
		playerv.Value = player.UserId
		print("Owner set to "..player.Name)
		ownerset = 1
	end
end)
sellpart.Touched:Connect(function(hit)
	if hit.Name == "Block" then

		local playername = players:GetNameFromUserIdAsync(playerv.Value)
		local Money = game.Players.playername.leaderstats.Money --playername doesnt work. how to fix it?
		Money.Value = Money.Value + 10
		hit:Destroy()
	end
end)

You would use Instance[member] syntax:

local Money = game.Players[playername].leaderstats.Money
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.