Hello i made a script for leaderstats that is supposed to save as coins th ecoins show up and add score to the leaderboard but this script is not saving the score like it is supposed to
how is anyone supposed to help you when you’re not showing the script
oops mb XDDDDDDDDDDDDDDDDDDD char limit is amazing
local DataStoreService = game:GetService(“DataStoreService”) --Gets the DataStoreService
local dataStore = DataStoreService:GetDataStore(“Test”) --Gives the Datastore a name
–//Function
local function saveData(player) --Create out own function for saving data
local tableToSave = { --Creates a table for our values
player.leaderstats.Coins.Value; --Saves the first value
player.leaderstats.Level.Value; --Saves the second value
} --You can continue the list in the same order by adding “player.leaderstats.IntValueName.Value;”
local success, errorMessage = pcall(dataStore.SetAsync, dataStore, player.UserId, tableToSave) --Checks if datastore succeeded
if success then --If datastore success then
print("Data has been saved!") --Prints success
else --If datastore fails then
print("Data has not been saved!") --Prints failure
end
end
–//leaderstats
game.Players.PlayerAdded:Connect(function(player) --When a player joins the game
player.CharacterAdded:Wait() --Wait for the player to load
local leaderstats = Instance.new(“Folder”) --Creates a new folder for the player
leaderstats.Name = “leaderstats” --Sets Folder name to “leaderstats” --MAKE SURE YOU DON’T CHANGE THIS
leaderstats.Parent = player --Puts the Folder under the player
local points = Instance.new("IntValue") --Creates an IntValue
Coins.Name = "Coins" --Sets IntValue name to "Points" (If you change this make sure you change all of them)
Coins.Parent = leaderstats --Puts the IntValue under the "leaderstats" folder
Points.Value = 5 --Gives the IntValue Value to start off with
local Level = Instance.new("IntValue") --Creates an IntValue
Level.Name = "Level" --Sets IntValue name to "Wins" (If you change this make sure you change all of them)
Level.Parent = leaderstats --Puts the IntValue under the "leaderstats" folder
Level.Value = 123 --Gives the IntValue Value to start off with
local data = nil --Data is empty
local success, errorMessage = pcall(function()
data = dataStore:GetAsync(player.UserId) --Finds the player's UserId and data
end)
if success and data then --If UserId and Data found then
Coins.Value = data[1] --Sets points to the first set of data
Level.Value = data[2] --Sets wins to the first set of data
else --If UserId or Data not found then
print("The Player has no Data!") --Player has no data
warn(errorMessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player) --When player is leaving the game
saveData(player) --Save the player’s data
end)
game:BindToClose(function() --When the game’s servers are shutting down
for _, player in ipairs(game.Players:GetPlayers()) do --loop through all the players in the server
task.spawn(saveData, player) --save all the player’s data
end
end)
use ```lua at first and close with a another 3 ` at the end
this is a lua script
i dont understand what you mean
what you sent is an unreadable script put it between ``` at the start and the end to make it readable
il fix it just give me a moment
this is the code for datastore that doesnt work for me
ok you got a clear error at line 8,9 and 10 because you’re defining the variable points but you’re using coins change those lines to :
local Coins = Instance.new("IntValue")
Coins.Name = "Coins"
Coins.Parent = leaderstats
Coins.Value = 5
10 has no line wdym it just blank
mb its 27,28,29 and 30 i didnt see things well u didnt ss the first half of line numbers
here is full ss of the scriptt
yes i know its lines 27 to 30 change them to the script i wrote
ok trying it now il reply when im done testing
im pretty sure i put everything in right
are the script in the ss and this one conflicting?
local db = true
script.Parent.Touched:connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) ~= nil then
if db == true then
db = false
script.Parent.Transparency = 1
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 500
script.Sound:Play()
script.Parent.Transparency = 1
wait(1)
db = true
script.Parent.Transparency = 0
end
end
end)