leaderstats not working (Never thought they won't) - lua

So, my leaderstats is not working. It should create a folder inside my player, but it doesn't.
Tried some things to fix, but nothing helped. (This intelligent Ai doesn't want me to post this again)
Here are all of my code in leaderstats:
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local RunService = game:GetService("RunService")
local ServerStorage
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local toolConfig = require(ReplicatedStorage:FindFirstChild("Config"):FindFirstChild("ToolConfig"))
local dataStore = DataStoreService:GetDataStore("Test")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local rebirths = Instance.new("NumberValue")
rebirths.Name = "Rebirths"
rebirths.Parent = leaderstats
local cash = Instance.new("NumberValue")
cash.Name = "Cash"
cash.Parent = leaderstats
local rebirths
local cash
rebirths = dataStore:GetAsync(player.UserId.."_Rebirths")
cash = dataStore:GetAsync(player.UserId.."_Cash")
if rebirths ~= nil then
player.leaderstats.Rebirths.Value = rebirths
end
if cash ~= nil then
player.leaderstats.Cash.Value = cash
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local succes, errormsg = pcall(function()
dataStore:SetAsync(player.UserId.."_Rebirths", player.leaderstats.Rebirths.Value)
dataStore:SetAsync(player.UserId.."_Cash", player.leaderstats.Cash.Value)
end)
if errormsg then
print ("Data error!")
end
end)

1: You forgot to assign serverstorage.
2. Based directly off the code, it seems like the code is on Roblox. You made the mistake of forgetting to check the developer console. That should help.

Related

Roblox Studio (Lua) - Loading Data (Not Working)

This is my datastore script, it has leaderstats incorporated. I an trying to save & load the Clicks and the Rebirths that the player accumulated. When I leave it told me that the data was saved but when I join there Isn't any data loaded
Can someone please help me, tell me what am i doing wrong?
I also have "Enable Studio Acces to API Services" set to enabled. This problem persists with every other script i use.
local DataStoreService = game:GetService("DataStoreService")
local PlayerData = DataStoreService:GetDataStore("Data_2") -- Change the string value inbetween the "" to reset/change data stores
local LoadData = true -- Don't edit
local CreateData = true -- Don't edit
local function OnPlayerJoin(player)
local Leaderstats = Instance.new("Folder")
Leaderstats.Name = "leaderstats"
Leaderstats.Parent = player
local Clicks = Instance.new("IntValue")
Clicks.Name = "Clicks"
Clicks.Parent = Leaderstats
local Rebirths = Instance.new("IntValue")
Rebirths.Name = "Rebirths"
Rebirths.Parent = Leaderstats
local PlayerUserId = "Player_"..player.UserId
local data = PlayerData:GetAsync(PlayerUserId)
if data and LoadData == true then
warn("Loading "..PlayerUserId.." Data!")
Clicks.Value = data["Clicks"]
Rebirths.Value = data["Rebirths"]
print("Loaded "..PlayerUserId.." Data! 👍")
elseif CreateData == true then
warn("Creating "..PlayerUserId.." Data!")
Clicks.Value = 0
Rebirths.Value = 0
print("Created "..PlayerUserId.." Data! 👍")
else
warn("Check StoreData and CreateData, they may be off! ⚠️")
end
end
local function create_table(player)
local player_stats = {}
for _, stat in pairs(player.leaderstats:GetChildren()) do
player_stats[stat.Name] = stat.Value
end
return player_stats
end
local function OnPlayerExit(player)
local player_stats = create_table(player)
local success, err = pcall(function()
local PlayerUserId = "Player_"..player.UserId
PlayerData:SetAsync(PlayerUserId, player_stats)
print("Data Save Success!")
end)
if not success then
warn("Data Save Has Failed! ⚠️")
local PlayerUserId = "Player_"..player.UserId
PlayerData:SetAsync(PlayerUserId, player_stats)
warn("Retrying Data Save! ⚠️")
end
end
game.Players.PlayerAdded:Connect(OnPlayerJoin)
game.Players.PlayerRemoving:Connect(OnPlayerExit)

Why LeaderStats folder doesn`t creates| Roblox Studio, Lua

My leaderstats script doesnt work for some reason. I dont know why.
When i testing game in roblox studio folder just doesnt creating.
Because of the bug some information doesn`t loads.
There is the code (Script located in ServerScriptStorage):
wait(1)
print("Script LeaderStats started!")
local dataStoreService = game:GetService("DataStoreService")
local clicksDataStore = dataStoreService:GetDataStore("Clicks")
game.Players.PlayerAdded:Connect(function(Player)
local PStats = Instance.new("Folder", Player)
PStats.Name = "PStats"
local clicks = Instance.new("IntValue", PStats)
clicks.Name = "Clicks"
clicks.Value = 0
local playerUserId = "player_"..Player.UserId
-- loading data
local clicksData
local success, errormessage = pcall(function()
clicksData = clicksDataStore:GetAsync(playerUserId, clicksValue)
end)
if success then
clicks.Value = clicksData
end
end)
-- saving data
game.Players.PlayerRemoving:Connect(function(Player)
local playerUserId = "player_"..Player.UserId
local clicksValue = Player.PStats.Clicks.Value
local success, errormessage = pcall(function()
clicksDataStore:SetAsync(playerUserId, clicksValue)
end)
end)
game:BindToClose(function(Player)
for _, Player in pairs(game.Players:GetPlayers()) do
local playerUserId = "player_"..Player.UserId
local clicksValue = Player.PStats.Clicks.Value
local success, errormessage = pcall(function(Player)
clicksDataStore:SetAsync(playerUserId, clicksValue)
end)
end
end)
I tried putting it in workspace, but folder didn`t create.
Make sure it's a Server Script inside of ServerScriptService.
replace line 31 with
clicksData = clicksDataStore:GetAsync(playerUserId)
If you want it to show as a leaderboard, replace line 15 with
PStats.Name = "leaderstats"

How do I remove a leaderstats value

I Cant get rid of Mana, I tried to delete the folder and when I went back in the game the folder was still there what should I do?...
CODE--
DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Clicks = Instance.new('IntValue')
Clicks.Name = "Clicks"
Clicks.Parent = leaderstats
local Rebirths = Instance.new('IntValue')
Rebirths.Name = "Rebirths"
Rebirths.Parent = leaderstats
local playerUserId = "Player_"..player.UserId
-- Load Data
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(playerUserId)
end)
if success then
Clicks.Value = data.Clicks
Rebirths.Value = data.Rebirths
-- Set our data equal to the current Clicks
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerUserId = "Player_"..player.UserId
local data = {
Clicks = player.leaderstats.Clicks.Value;
Rebirths = player.leaderstats.Rebirths.Value;
}
local success, errormessage = pcall(function()
myDataStore:SetAsync(playerUserId, data)
end)
if success then
print("Data successfully saved!")
else
print("There was an error!")
warn(errormessage)
end
end)
If you can't find the script that creates the leaderstat you could use script like the following to delete the extra leaderstats folder containing the Mana value. I would recommend this because the extra leaderstat has to be generated somewhere and it's best to just get rid of the script creating it.
Anyway you could try this: Add the following code to the ServerScriptService
game.Players.OnPlayerAdded:Connect(function(player)
wait(5) -- to wait for the script that adds the leaderstats to run
for _, child in ipairs(player:GetChildren()) do
if child.Name == "leaderstats" then
for _, value in ipairs(child:GetChildren()) do
if value.Name == "Mana" then
child:Destroy()
end
end
end
end
end)
What the above script does is it checks if a leaderstats folder inside the player exists with the value Mana, if it does, it will destroy the leaderstats folder.
The code posted above is not adding the extra leaderstats folder and value mana. User the search in the explorer to find any scripts in your game. Just type script into your search. Then open each file in your game hit Ctl + F on your keyboard and find Mana in each script.
Why this could happen? There are many assets from the toolbox that come bundled with scripts which could be one cause of your problem, but it can also happen because of plugins you have installed which add leaderstats to your game.

Debounce is not a valid member of Folder

Alright so I got this script from a tutorial and this is what I typed for the script Remotes
local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteData = game:GetService("ServerStorage"):WaitForChild("RemoteData")
local cooldown = 1
replicatedStorage.Remotes.Lift.OnServerEvent:Connect(function(player)
print("event launched")
if not remoteData:FindFirstChild(player.Name) then return "NoFolder" end
local debounce = remoteData[player.Name].Debounce
if not debounce then
debounce.Value = true
player.leaderstats.Power.Value = player.leaderstats.Power.Value + 5 * (player.leaderstats.Prestiges.Value + 1)
wait(cooldown)
debounce.Value = false
end
end)
but I have seem to get the error which is
Debounce is not a valid member of Folder "ServerStorage.RemoteData.OmegaHero2010"
here are some other scripts
Stats
local serverStorage = game:GetService("ServerStorage")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local power = Instance.new("NumberValue")
power.Name = "Power"
power.Parent = leaderstats
local prestige = Instance.new("NumberValue")
prestige.Name = "Prestiges"
prestige.Parent = leaderstats
local dataFolder = Instance.new("Folder")
dataFolder.Name = player.Name
dataFolder.Parent = serverStorage.RemoteData
local debounce = Instance.new("BoolValue")
debounce.Parent = dataFolder
end)
Module
local module = {}
local replicatedStorage = game:GetService("ReplicatedStorage")
function module.Lift()
replicatedStorage.Remotes.Lift:FireServer()
end
return module
Local Script
local module = require(script.Parent:WaitForChild("ModuleScript"))
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
script.Parent.Activated:Connect(function()
module.Lift()
end)
what is the problem here?
The line local debounce = remoteData[player.Name].Debounce is failing to find the child named "Debounce".
So, looking at how you created the BoolValue in ServerScriptService :
local debounce = Instance.new("BoolValue")
debounce.Parent = dataFolder
You never set the Name property. So there is a BoolValue in the player's folder but it is named "BoolValue", not "Debounce". To fix your error, just add the line to set the Name.
debounce.Name = "Debounce"

Roblox Studio (LUA) - Saving Table to DataStore (Not Working)

I have been trying multiple ways to save two values to a DataStore whilst using pcall for error handling, and I cannot seem to figure out a solution to make my code work.
Any suggestion on changes?
local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Parent = leaderstats
local wins = Instance.new("IntValue")
wins.Name = "Wins"
wins.Parent = leaderstats
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(player.UserId.."-user")
end)
if success then
cash.Value = data[1] or 0
wins.Value = data[2] or 0
else
print("There was an error while fetching your data.")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
myDataStore:SetAsync(player.UserId.."-user", {player.leaderstats.Cash.Value, player.leaderstats.Wins.Value})
end)
if success then
print("Player data successfully saved.")
else
print("There was an error saving your data.")
warn(errormessage)
end
end)

Resources