So I have made a script that is suppose to take away Candy from the player and give them Cash instead, it is located in a button inside a gui, however, it doesn't seem to work properly. It takes away the candy and adds money, but it does not save.
I initially thought it was an issue with the datastore but it turns out that the issue is within the script, thanks =^)
player = game.Players.LocalPlayer:findFirstChild("leaderstats")
money2 = player:findFirstChild("Moneys")
money = player:findFirstChild("Candy")
price = 6
extra = 2
text = { "Here you go! Would you like to trade more candy?"}
function Click()
wait()
if money.Value >= price then
money.Value = money.Value - price
money2.Value = money2.Value + extra
local randText = text[math.random(#text)]
for a=1,string.len(randText) do
script.Parent.Parent.Dialog.Text = string.sub(randText,1,a)..""
wait(.01)
end
end
end
script.Parent.MouseButton1Down:connect(Click)

1 comment
It doesn't change it unfortunately. A note to add on, when it takes away the candy, if the player gets more candy later on, it will combine it to the previous amount. For example, if I had 90 candy and I got rid of that and exchanged it for money but then soon got 6 candy, it would give me 96 instead of just 6.