How to make it so that a script when it is looking for the past uses the variable for player and doesn't search for "player"?

Me and a friend are trying to make a tycoon from scratch to help learn us scripting. The script we are using is for a block that you step on that transfers money to you. We trying to look for the leaderstat variable that is for how much money you have, and we have another variable called “moneytogive” which is the money that you earned but is not in your inventory yet.

So when we try to run the game, it looks for the specific word “player” instead of the variable we have called “player”

The script we are using:

workspace.d.Touched:Connect(function(hit)
    print("hit")
    local money = game.ServerStorage.moneytogive.Value
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    print(player)
    game.Players.player.leaderstats.Cash.Value = game.Players.player.leaderstats.Cash.Value + money
    print("hit it")
end)

So from what I understand you’re trying to do something like this

local serverStorage = game:GetService("ServerStorage")
-- With GetService we can ensure that the service is loaded when we get it
-- It can also get a service when someone has renamed it
-- Such as if ServerStorage was named "NotSS" then
-- You couldn't use game.ServerStorage
-- But you could still use game:GetService() on it
-- This is void for workspace because it has it's own keyword!
local cashToGive = serverStorage:WaitForChild("CashToGive")
local partToTouch = workspace:WaitForChild("d")
-- With wait for child we can ensure that the part exsits before we write out code
partToTouch.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	
	if player then
		local leaderstats = player.leaderstats
		
		if leaderstats and leaderstats.Cash then
			-- This line above checks if leaderstats exsits and leaderstats.Cash exists
			leaderstats.Cash.Value = leaderstats.Cash.Value + cashToGive.Value
			-- The line above will only work if CashToGive is an *int value* or a number value.
			-- For this use I would use an IntValue.
		end
	end
end)