--Variables
local DataStore2 = require(game.ServerScriptService.DataModule)
local MainKey = "MainKey"
DataStore2.Combine(MainKey,"Stats","Cars")
--Data Table
local function SetDataTable()
local UserData = {
Stats = {
["Cash"] = 50000000;
};
Cars = {
["Hyperno"] = false;
["Explorus"] = false;
["Trofeo"] = false;
};
}
return UserData -- get datatable
end
game.Players.PlayerAdded:Connect(function(plr)
local UserData = DataStore2(MainKey,plr):Get(SetDataTable())
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
local achfolder = Instance.new("Folder")
achfolder.Name = "CarFolder"
local Cash = Instance.new("IntValue")
Cash.Name = "Cash"
local Hyperno = Instance.new("BoolValue")
Hyperno.Name = "Hyperno"
local Explorus = Instance.new("BoolValue")
Explorus.Name = "Explorus"
local Trofeo = Instance.new("BoolValue")
Trofeo.Name = "Trofeo"
local StatsData = DataStore2("Stats",plr)
local CarsData = DataStore2("Cars",plr)
local function UpdateStats(UpdatedValue)
Cash.Value = StatsData:Get(UpdatedValue).Cash
end
StatsData:OnUpdate(UpdateStats)
local function UpdateCar(UpdatedValue)
Hyperno.Value = CarsData:Get(UpdatedValue).Hyperno
Explorus.Value = CarsData:Get(UpdatedValue).Explorus
Trofeo.Value = CarsData:Get(UpdatedValue).Trofeo
end
UpdateStats(UserData.Stats)
UpdateCar(UserData.Cars)
StatsData:OnUpdate(UpdateStats)
CarsData:OnUpdate(UpdateCar)
leaderstats.Parent = plr
achfolder.Parent = plr
Cash.Parent = leaderstats
Hyperno.Parent = achfolder
Explorus.Parent = achfolder
Trofeo.Parent = achfolder
game.ReplicatedStorage:WaitForChild("CheckPrice").OnServerInvoke = function(player,NameOfCar)
return game.ServerStorage.Cars:FindFirstChild(NameOfCar).Price.Value
end
game.ReplicatedStorage:WaitForChild("CheckPurchase").OnServerInvoke = function(player,NameOfCar)
return game.Players:FindFirstChild(player.Name).CarFolder:FindFirstChild(NameOfCar).Value
end
end)
game.ReplicatedStorage:WaitForChild("SpawnCar").OnServerEvent:Connect(function(player,NameOfCar)
local car = game.ServerStorage.Cars:FindFirstChild(NameOfCar):Clone()
car:SetPrimaryPartCFrame(player.Character.HumanoidRootPart.CFrame + Vector3.new(0,0,15))
car.Parent = workspace
car:MakeJoints()
car.Name = player.Name.."'s"..NameOfCar
end
)
game.ReplicatedStorage:WaitForChild("UnlockCar").OnServerInvoke = function(player,NameOfCar)
if game.Players:FindFirstChild(player.Name).CarFolder:FindFirstChild(NameOfCar).Value == false then
print (game.Players:FindFirstChild(player.Name).CarFolder:FindFirstChild(NameOfCar))
game.Players:FindFirstChild(player.Name).CarFolder:FindFirstChild(NameOfCar).Value = true
return game.Players:FindFirstChild(player.Name).CarFolder:FindFirstChild(NameOfCar).Value
end
end
我正在尝试使用DataStores2来保存boolvalues和Cash值。购买脚本可以完美地运行,但是我要向您展示的主要脚本既没有节省现金,也没有确定玩家是否拥有赛车的布尔值。
我该如何解决?
我尝试查看教程,而我遵循的主要教程是https://www.youtube.com/watch?v=hmRBvZD1pRw。
大多数代码都基于他的代码。我做错了什么?我该怎么做才能真正保存它?
你为什么在这里发布地狱