【发布时间】:2020-05-22 18:34:09
【问题描述】:
我在 Roblox 工作室的货币脚本中遇到错误
local currencyName = "Coins"
local DataStore = game:GetService(("DataStoreService"):GetDataStore("TestDataStore")
game.Players.PlayerAdded:Connect(function(player)
local folder = Instance.new("Folder")
folder.Name = "leaderstats"
folder.Parent = player
local currency = Instance.new("IntValue")
currency.Name = currencyName
currency.Parent = folder
local ID =""currencyName.."-"..player.UserId
local savedData = nil
pcall(function())
savedData = DataStore:GetAsync(ID)
end)
if savedData ~= nil then
curreny.Value = savedData
print("Data loaded")
else
currency.Value = 10 -- amount to a new player
print("New player to the game")
end
end)
game.Plyers.PlayerRemoving:Connect(function(player)
local ID =""currencyName.."-"..player.UserId
DataStore:SetAsync(ID,player.leaderstats[currencyName].Value)
end)
game:BindToClose(function()
-- when game is ready to shut down
for i, player in pairs(game.Players:GetPlayers()) do
if player then
player:KICK("This game is shutting down")
end
end
wait(5)
end)
它在第 3 行给了我这个错误:
10:30:47.749 - CurrencyScript.Script:3: 预期为 ')'(在第 2 行关闭 '('),得到 'game'
10:30:49.909 - InsertService 不能用于从客户端加载资产
【问题讨论】: