ServerScriptService.Script:36:尝试使用“CoinsAmount”索引数字(Roblox Studio)

问题描述 投票:0回答:1

所以我正在使用 luau 在 roblox studio 上为模拟器类型游戏制作数据存储,并得到了这个我无法破解的错误。

这是代码

local DataStoreService = game:GetService("DataStoreService")
local CoinsStore = DataStoreService:GetDataStore("CoinsStore")

game.Players.PlayerAdded:Connect(function(player)
    local stats = Instance.new("Folder", player)
    stats.Name = "Stats"

    local leaderstats = Instance.new("Folder", player)
    leaderstats.Name = "leaderstats"

    local Coins = Instance.new("IntValue", leaderstats)
    Coins.Name = "Coins"

    local Rebirths = Instance.new("IntValue", leaderstats)
    Rebirths.Name = "Rebirths"

    local StomachMaxSpace = Instance.new("IntValue", stats)
    StomachMaxSpace.Name = "StomachMaxSpace"

    local Stomach = Instance.new("IntValue", stats)
    Stomach.Name = "Stomach"
    
    local UID = player.UserId
    
    --Load Data
    
    local data
    
    
    local success, errormessage = pcall(function()
        
         data = CoinsStore:GetAsync(UID)
    end)
    
    if success then
        Coins.Value = data.CoinsAmount
        StomachMaxSpace.Value = data.StomachCapacity
        Stomach.Value = data.Stomach
    end
    
        
    
end)   

--save data

game.Players.PlayerRemoving:Connect(function(player)
    local UID = player.UserId
    
    local data = {
        CoinsAmount = player.leaderstats.Coins.Value,
        StomachCapacity = player.Stats.StomachMaxSpace.Value,
        Stomach = player.Stats.Stomach.Value
    }   
    
    local success, errormessage = pcall(function()
        CoinsStore:SetAsync(UID, data)
    end)
    
    if success then
        print("All Data Saved")
    end
    
    
    
end)

请帮我解决错误,因为我需要把这个游戏推出

错误:ServerScriptService.Script:36:尝试使用“CoinsAmount”索引数字

lua roblox luau roblox-studio
1个回答
0
投票

我相信

CoinsStore:GetAsync(UID)
返回一个数字,如果此函数返回错误代码,那么您可能还想在继续之前检查该函数的返回值。

© www.soinside.com 2019 - 2024. All rights reserved.