我制作了一个 Leaderstats 脚本,其中包含 2 个文件夹和 6 个统计数据。当我测试游戏时,没有任何统计数据加载。这是脚本:
local DataStore = game:GetService("DataStoreService"):GetDataStore("ValueSave")
local DataStore2 = game:GetService("DataStoreService"):GetDataStore("ValueSave2")
local DataStore3 = game:GetService("DataStoreService"):GetDataStore("ValueSave3")
local DataStore4 = game:GetService("DataStoreService"):GetDataStore("ValueSave4")
local DataStore5 = game:GetService("DataStoreService"):GetDataStore("ValueSave5")
local DataStore6 = game:GetService("DataStoreService"):GetDataStore("ValueSave6")
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder", plr)
leaderstats.Name = "leaderstats"
local plrstats = Instance.new("Folder", plr)
plrstats.Name = "Multipliers"
local cash = Instance.new("IntValue", leaderstats)
cash.Name = "Jump"
cash.Value = DataStore:GetAsync(plr.UserId) or 1
local cash1 = Instance.new("IntValue", leaderstats)
cash.Name = "Run"
cash.Value = DataStore5:GetAsync(plr.UserId) or 1
local cash2 = Instance.new("IntValue", leaderstats)
cash.Name = "Climb"
cash.Value = DataStore6:GetAsync(plr.UserId) or 1
local Upgrade = Instance.new("IntValue", plrstats)
Upgrade.Name = "ClimbMultiplier"
Upgrade.Value = DataStore4:GetAsync(plr.UserId) or 1
local multi = Instance.new("IntValue", plrstats)
multi.Name = "RunMultiplier"
multi.Value = DataStore2:GetAsync(plr.UserId) or 1
local cost = Instance.new("IntValue", plrstats)
cost.Name = "JumpMultiplier"
cost.Value = DataStore3:GetAsync(plr.UserId) or 1
cash.Changed:Connect(function()
DataStore:SetAsync(plr.UserId, cash.Value)
end)
Upgrade.Changed:Connect(function()
DataStore4:SetAsync(plr.UserId, Upgrade.Value)
end)
cost.Changed:Connect(function()
DataStore3:SetAsync(plr.UserId, cost.Value)
end)
multi.Changed:Connect(function()
DataStore2:SetAsync(plr.UserId, multi.Value)
end)
cash1.Changed:Connect(function()
DataStore5:SetAsync(plr.UserId, cash1.Value)
end)
cash2.Changed:Connect(function()
DataStore6:SetAsync(plr.UserId, cash2.Value)
end)
end)
game.Players.PlayerRemoving:Connect(function(plr)
DataStore:SetAsync(plr.UserId, plr.leaderstats.Cash.Value)
DataStore4:SetAsync(plr.UserId, plr.Multipliers.Upgrade.Value)
DataStore3:SetAsync(plr.UserId, plr.Multipliers.Cost.Value)
DataStore2:SetAsync(plr.UserId, plr.Multipliers.multi.Value)
DataStore5:SetAsync(plr.UserId, plr.leaderstats.cash1.Value)
DataStore6:SetAsync(plr.UserId, plr.leaderstats.cash2.Value)
end)
我加入后,输出没有错误。这个脚本有什么问题?我可以做什么来修复它?请帮忙。
我需要添加这些词来发布我的问题。
local DataStore,DataStore2,DataStore3,DataStore4,DataStore5,DataStore6
game.Players.PlayerAdded:Connect(function(plr)
while not DataStore6 do task.wait()end
local leaderstats = Instance.new("Folder", plr)
leaderstats.Name = "leaderstats"
local plrstats = Instance.new("Folder", plr)
plrstats.Name = "Multipliers"
local cash = Instance.new("IntValue", leaderstats)
cash.Name = "Jump"
cash.Value = DataStore:GetAsync(plr.UserId) or 1
local cash1 = Instance.new("IntValue", leaderstats)
cash.Name = "Run"
cash.Value = DataStore5:GetAsync(plr.UserId) or 1
local cash2 = Instance.new("IntValue", leaderstats)
cash.Name = "Climb"
cash.Value = DataStore6:GetAsync(plr.UserId) or 1
local Upgrade = Instance.new("IntValue", plrstats)
Upgrade.Name = "ClimbMultiplier"
Upgrade.Value = DataStore4:GetAsync(plr.UserId) or 1
local multi = Instance.new("IntValue", plrstats)
multi.Name = "RunMultiplier"
multi.Value = DataStore2:GetAsync(plr.UserId) or 1
local cost = Instance.new("IntValue", plrstats)
cost.Name = "JumpMultiplier"
cost.Value = DataStore3:GetAsync(plr.UserId) or 1
cash.Changed:Connect(function()
DataStore:SetAsync(plr.UserId, cash.Value)
end)
Upgrade.Changed:Connect(function()
DataStore4:SetAsync(plr.UserId, Upgrade.Value)
end)
cost.Changed:Connect(function()
DataStore3:SetAsync(plr.UserId, cost.Value)
end)
multi.Changed:Connect(function()
DataStore2:SetAsync(plr.UserId, multi.Value)
end)
cash1.Changed:Connect(function()
DataStore5:SetAsync(plr.UserId, cash1.Value)
end)
cash2.Changed:Connect(function()
DataStore6:SetAsync(plr.UserId, cash2.Value)
end)
end)
game.Players.PlayerRemoving:Connect(function(plr)
DataStore:SetAsync(plr.UserId, plr.leaderstats.Cash.Value)
DataStore4:SetAsync(plr.UserId, plr.Multipliers.Upgrade.Value)
DataStore3:SetAsync(plr.UserId, plr.Multipliers.Cost.Value)
DataStore2:SetAsync(plr.UserId, plr.Multipliers.multi.Value)
DataStore5:SetAsync(plr.UserId, plr.leaderstats.cash1.Value)
DataStore6:SetAsync(plr.UserId, plr.leaderstats.cash2.Value)
end)
DataStore = game:GetService("DataStoreService"):GetDataStore("ValueSave")
DataStore2 = game:GetService("DataStoreService"):GetDataStore("ValueSave2")
DataStore3 = game:GetService("DataStoreService"):GetDataStore("ValueSave3")
DataStore4 = game:GetService("DataStoreService"):GetDataStore("ValueSave4")
DataStore5 = game:GetService("DataStoreService"):GetDataStore("ValueSave5")
DataStore6 = game:GetService("DataStoreService"):GetDataStore("ValueSave6")
if script:IsDescendantOf(workspace)then error(tick())end