So I'm creating a tool to give me plus 1 coin so I created a data store leader stats it works fine i tested it with the developer console but it doesn't save the tool coins here is the data store leaderstats :
local DataStore = game:GetService("DataStoreService") local DS1 = DataStore:GetDataStore("CoinsDataStore") game.Players.PlayerAdded:Connect(function(plr) local leaderstats = Instance.new("Folder",plr) leaderstats.Name = "leaderstats" local Coins = Instance.new("IntValue",leaderstats) Coins.Name = "Coins" Coins.Value = 0 Coins.Value = DS1:GetAsync(plr.UserId) or 0 DS1:SetAsync(plr.UserId,Coins.Value) Coins.Changed:Connect(function(plr) DS1:SetAsync(plr.UserId,Coins.Value) end) end)
-- Tool Script that give +1 click when clicking a tool local leaderstats = game.Players.LocalPlayer.leaderstats local Coins = leaderstats.Coins local Cooldown = false script.Parent.Activated:Connect(function() if Cooldown == true then return end if Cooldown == false then Cooldown = true Coins.Value = Coins.Value +1 wait(0.8) Cooldown = false end end)
It's not saving my coins from the tool when i click i do get +1 coins but it dosen't and i have not problem with my datastore what did i do that it's not saving what i get from the tools.
I assume you're using a server script for this, if so, the value "LocalPlayer" is not replicated, this means only a local script can read it. If you're using a local script, use a server script or remote events (not reccomended, never trust the client.), a solution would be:
-- Creates empty variables to be edited later on. (This is a ServerScript) local leaderstats local Coins local Cooldown = false local player local character script.Parent.Equipped:Connect(function() -- This will assign the values to the previously mentioned empty variables. character = script.Parent.Parent player = game.Players:GetPlayerFromCharacter(character) leaderstats = player:WaitForChild("leaderstats") Coins = leaderstats:WaitForChild("Coins") end) script.Parent.Activated:Connect(function() -- Once activated, change the value of Coins. if Cooldown == true then return end if Cooldown == false then Cooldown = true Coins.Value = Coins.Value +1 wait(0.8) Cooldown = false end end)
Hope this helps!