领导者统计数据不起作用(从没想过他们不会)



所以,我的领导统计不起作用。它应该在播放器中创建一个文件夹,但它没有。尝试了一些方法来修复,但无济于事。(这个智能Ai不希望我再发这篇文章)以下是我在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:您忘记分配服务器存储。2. 直接从代码来看,代码似乎是在Roblox上。你犯了忘记检查开发者控制台的错误。这应该有帮助。