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)

3 comments
All scripts should be your own. Do not take a free model and expect us to fix it (in this case, datastore2)
Why don't you edit the leaderstats instead of the datastore?
Datastore2 is not considered a free model. If you think so, it'd make all the games in the front page "free modeled". It is made for people to use it, as it is way better than the normal datastore.