I am currently coding a trick or treat game. I have two main values = Money and Candy.
I am storing my values via leaderstats, which then translate and update a PlayerGui, but thats not where my issue is at.
I want players to be able to sell their candy for 2x it's value. Say you have 30 candy, you can sell it for 60 Moneys.
This system works just fine when I set a predetermined candy value via my leaderboard script in ServerScriptServices:
local candy = Instance.new("IntValue") candy.Name = "Candy" candy.Value = 30 candy.Parent = leaderstats
However, when I try to sell candy that was obtained via trick or treating (given by the server to the client), nothing happens. It will only sell the candy that was already there. Here is my code for my sell system.
local rs = game:GetService("ReplicatedStorage") local event = rs:WaitForChild("SellCandy") function sell(plr) plr.leaderstats.Money.Value += (plr.leaderstats.Candy.Value) * 2 print(plr.leaderstats.Candy.Value.." Candies sold!") wait(1) plr.leaderstats.Candy.Value = 0 end event.OnServerEvent:Connect(sell)
I am unsure why this is happening. Can anybody help me with this?