Hi! I recently implented a shop system, (thanks to the people that helped me) but something is wrong. Let’s say I buy an upgrade, it takes my currency away. Then, I go grab some more. It returns back to its original value before I bought the upgrade!
--Basically what happens if the corn is touched
local Players = game:GetService("Players")
local corn = script.Parent
local RepStorage = game:GetService("ReplicatedStorage")
local cornamountval = RepStorage:WaitForChild("cornamount")
local cornamount = game.StarterGui.cornamount.Frame:WaitForChild("cornamountlabel")
local CornHarvestEvent = RepStorage:WaitForChild("CornHarvestEvent")
corn.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player then
corn:Destroy()
cornamountval.Value = cornamountval.Value - 1
local leaderstats = player.leaderstats
local cornStat = leaderstats:FindFirstChild("corn")
if cornStat then
cornStat.Value = cornStat.Value + 10
end
CornHarvestEvent:FireClient(player)
end
end)