Tycoon money earned in different ways not working

Hello i am currently making a tycoon and I have made a tree which gives money every 3 seconds in the tycoon if I buy the tree I get the money and it shows on leaderboard. But the problem is when I try to buy something in my tycoon it doesnt work and when I collect the cash from the regular droppers it resets the value but the money received from droppers work. I have looked into it but couldnt find a solution. Could it be something with local money and servermoney? The tree script is local.

This is my script for the tree dropper
local lifetime = 3

while true do
wait(5)
local pos = script.Parent
local devilFruitUnion = game.ServerStorage:FindFirstChild(“DevilFruit”)

if devilFruitUnion then
	local devilFruitClone = devilFruitUnion:Clone()
	devilFruitClone.CFrame = pos.CFrame + Vector3.new(0, 0, 0) -- Adjust the Vector3 values for the desired spawn position
	devilFruitClone.Parent = game.Workspace
	devilFruitClone.Velocity = Vector3.new(0, 0, 0)
	game:GetService("Debris"):AddItem(devilFruitClone, lifetime)

	wait(3) -- Wait for 3 seconds before despawning

	-- Check if the Devil Fruit is in Workspace (on the ground)
	if devilFruitClone:IsDescendantOf(game.Workspace) then
		for _, player in pairs(game.Players:GetPlayers()) do
			local leaderstats = player:FindFirstChild("leaderstats")
			if leaderstats then
				local Cash = leaderstats:FindFirstChild("Cash")
				if Cash then
					Cash.Value = Cash.Value + 10 -- Give players 10 beli
				end
			end
		end
	end

	devilFruitClone:Remove()
end

end

I would be very happy if I can fix this problem! Thanks to everyone who takes his time to help.

I’m not really sure which part of the two sources is broken but this definitely is. If you are adding money in the tree script, it will not replicate to and change on the server due to client-server boundary, instead use a RemoteEvent to notify the server about the money change and do it there

Thanks for your answer I appreciate it very much. I now made this script with a remote event and I also created a remoteevent in replicatedstorage named “AddMoneyEvent” and the last thing I added is a serverscript. The problem here is that there is no money added now I dont get money from the trees. What did I do wrong I tried some solutions but I cant find an answer. I would be very happy if I can fix this issue. Thanks.

droppertreescript

local lifetime = 3 – Adjust this value as needed (e.g., 3 for a 3-second lifetime)

– Create a RemoteEvent
local addMoneyEvent = Instance.new(“RemoteEvent”)
addMoneyEvent.Name = “AddMoneyEvent”
addMoneyEvent.Parent = game.ReplicatedStorage

while true do
wait(5)
local pos = script.Parent
local devilFruitUnion = game.ServerStorage:FindFirstChild(“DevilFruit”) – Replace with the name of your Devil Fruit union

if devilFruitUnion then
	local devilFruitClone = devilFruitUnion:Clone()
	devilFruitClone.CFrame = pos.CFrame + Vector3.new(0, 0, 0) -- Adjust the Vector3 values for the desired spawn position
	devilFruitClone.Parent = game.Workspace
	devilFruitClone.Velocity = Vector3.new(0, 0, 0)
	game:GetService("Debris"):AddItem(devilFruitClone, lifetime)

	wait(3) -- Wait for 3 seconds before despawning

	-- Check if the Devil Fruit is in Workspace (on the ground)
	if devilFruitClone:IsDescendantOf(game.Workspace) then
		-- Trigger the remote event to add money to players
		addMoneyEvent:FireAllClients(10) -- Give players 10 beli
	end

	devilFruitClone:Remove()
end

end

serverscript
local addMoneyEvent = game.ReplicatedStorage:WaitForChild(“AddMoneyEvent”)

addMoneyEvent.OnClientEvent:Connect(function(amount)
– Add the received amount of money to the player’s cash
local player = game.Players.LocalPlayer
local leaderstats = player:WaitForChild(“leaderstats”)
local Cash = leaderstats:WaitForChild(“Cash”)
Cash.Value = Cash.Value + amount
end)