【问题标题】:Getting an error in a currency script in ROBLOX studio在 ROBLOX 工作室的货币脚本中出现错误
【发布时间】: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 不能用于从客户端加载资产

【问题讨论】:

    标签: scripting roblox


    【解决方案1】:

    预期的 ')'(在第 2 行关闭 '('),

    第 2 行的括号太多。

    local DataStore = game:GetService("DataStoreService"):GetDataStore("TestDataStore")
    

    【讨论】:

      猜你喜欢
      • 2020-09-01
      • 2020-12-10
      • 1970-01-01
      • 2021-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多