Heres my issue. I learnt to create an Egg Opening System for my game with some of my friends. But when you click the part it does not remove the coins from the players balance using the :Set function from Datastore2. I don't understand why since there is no error code. But at the same time if i use CoinsStore:Increment(-1500) then it would say "Attempt to perform arithmetic (add) on a nil and a number." Any help would be appreciated.
Heres my code:
local Datastore2 = require(1936396537) local cost = 1500 local petModule = require(game.ServerScriptService:WaitForChild("PetModule")) script.Parent.ClickDetector.MouseClick:Connect(function(player) if player.leaderstats.Coins.Value >= cost then local CoinsStore = Datastore2("Coins", player) local Coins = player.leaderstats.Coins CoinsStore:Set(Coins.Value - 1500) local pet = petModule.chooseRandomPet() print(pet.Name.." was selected.") end end)
To subtract, you have to tell you're subtracting from the value like that:
-- how you do it Coins.Value = Coins.Value - 1500 -- not how you do it Coins.Value = -1500
So applying that to your script, i'd be:
CoinsStore:Set(Coins.Value = Coins.Value - 1500)
I never used datastore2, but if they didn't change anything then that should work. Your entire script:
local Datastore2 = require(1936396537) local cost = 1500 local petModule = require(game.ServerScriptService:WaitForChild("PetModule")) script.Parent.ClickDetector.MouseClick:Connect(function(player) if player.leaderstats.Coins.Value >= cost then local CoinsStore = Datastore2("Coins", player) local Coins = player.leaderstats.Coins CoinsStore:Set(Coins.Value = Coins.Value - 1500) local pet = petModule.chooseRandomPet() print(pet.Name.." was selected.") end end)
Hope this helped!