Selling Box Code not work

Hello,i want to make boxes you can sell! But not Working…

I tried to make it. with a Value and it not work, but why?

Idk why.

This is the Code for Leaderstats:

local function onPlayerJoin(player)

	local leaderstats = Instance.new("Folder")

	leaderstats.Name = "leaderstats"

	leaderstats.Parent = player




	local coins = Instance.new("IntValue")

	coins.Name = "Coins"

	coins.Value = 50

	coins.Parent = leaderstats

end




game.Players.PlayerAdded:Connect(onPlayerJoin)

and this is the giver

local part = script.Parent

local Players = game.Players.LocalPlayer

local function onTouch(otherPart)

	local Owner = otherPart.Parent:FindFirstChild("Owner")

	if Owner then

		local player = game.Players:FindFirstChild(otherPart.Owner.Value)
		
		local Plr = Players:FindFirstChild("player")

			Plr.leaderstats.Coins.Value = Plr.leaderstats.Coins.Value + 1 

		end

	end

part.Touched:Connect(onTouch)

It is nice when someone can help me! And im new here

The giver code doesn’t work

Plr = Players:FindFirstChild("player")

will look for a player named “player”, which I don’t believe you are looking for.


Additionally

local Players = game.Players.LocalPlayer

wont work


So regarding on how to fix this
We can use Players:GetPlayerFromCharacter() to get the character from the part (parent)

This script needs to be a server script

local part = script.Parent

local Players = game.Players -- not local player
local function onTouch(otherPart)
    local Owner = otherPart.Parent:FindFirstChild("Owner")
	if Owner then 
		local Plr =Players:GetPlayerFromCharacter(otherPart.Parent) -- getting player
	    Plr.leaderstats.Coins.Value = Plr.leaderstats.Coins.Value + 1 
	end
end

part.Touched:Connect(onTouch)

I made it nad not works but i uploaded a Image of it

Thanks for Helping!