So I have a script where you can break a tree and get wood from it. From 1 tree you get 20 wood. If I break 1 tree I get 20 wood without any problems. However, if I break another tree, the totalamount becomes 0 and then becomes 20 again. I can't figure it out.
This is my localscript:
local rp = game:GetService("ReplicatedStorage")
local TreeHarvest = rp:WaitForChild("TreeHarvest")
local player = game.Players.LocalPlayer
totalamount = 0
TreeHarvest.OnClientEvent:connect(function(plr, amount)
if player == plr then
local totalamount = totalamount + amount
print("You now have", totalamount, "wood.")
script.Parent.Text = totalamount
end
end)
