【问题标题】:My Roblox Studio script is sometimes having errors.. idk why我的 Roblox Studio 脚本有时会出错.. idk 为什么
【发布时间】:2020-09-11 20:56:43
【问题描述】:

所以.. 我一直在编写一个 GUI 来显示玩家的货币数量,数据存储 API 可以完美运行,但本地脚本不能(它是本地脚本,否则它只会在每次玩家的货币时更新它货币得到更新,这与我想要的相反) 好吧......有时它会将货币加载到 GUI 中,但有时它只是停留在原始文本上:“标签”而不是我当前的货币 (4600) 这是证据

通常会发生并且应该总是发生的事情

有时会发生和不应该发生的事情:

这是脚本,我试过在开始时等待,但原始代码在 while true do..

wait(game.Players.LocalPlayer:WaitForChild("Data")
wait(game.Players.LocalPlayer.Data:WaitForChild("Bells"))
while true do
    script.Parent.TextLabel.Text = game.Players.LocalPlayer:WaitForChild("Data"):WaitForChild("Bells").Value
    wait() --wait is for not making the loop break and stop the whole script
end

好吧..如果您想查看播放器中是否真的有数据,这是脚本,它需要一个 API (DataStore2)

--[Animal Crossing Roblox Edition Data Store]--
            --Bryan99354--
        --Module not mine--
--Made with a AlvinBlox tutorial--
--·.·.*[Get Data Store, do not erase]*.·.·--

local DataStore2 = require(1936396537)

--[Default Values]--

local DefaultValue_Bells = 300
local DefaultValue_CustomClothes = 0

--[Data Store Functions]--

game.Players.PlayerAdded:Connect(function(player)
    --[Data stores]--
    local BellsDataStore = DataStore2("Bells",player)

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

    Bells = Instance.new("IntValue",Data)
    Bells.Name = "Bells"

    local CustomClothesDataStore = DataStore2("CustomClothes",player)

    local CustomClothes = Instance.new("IntValue",Data)
    CustomClothes.Name = "CustomClothes"

    local function CustomClothesUpdate(UpdatedValue)
        CustomClothes.Value = CustomClothesDataStore:Get(UpdatedValue)
    end

    local function BellsUpdate(UpdatedValue)
        Bells.Value = BellsDataStore:Get(UpdatedValue)
    end

    BellsUpdate(DefaultValue_Bells)
    CustomClothesUpdate(DefaultValue_CustomClothes)

    BellsDataStore:OnUpdate(BellsUpdate)
    CustomClothesDataStore:OnUpdate(CustomClothesUpdate)
end)

--[test and reference functions]--

workspace.TestDevPointGiver.ClickDetector.MouseClick:Connect(function(player)
    local BellsDataStore = DataStore2("Bells",player)
    BellsDataStore:Increment(50,DefaultValue_Bells)
end)
workspace.TestDevCustomClothesGiver.ClickDetector.MouseClick:Connect(function(player)
    local CustomClothesDataStore = DataStore2("CustomClothes",player)
    CustomClothesDataStore:Increment(50,DefaultValue_CustomClothes)
end)

创建“Data”和“Bells”的代码位于注释中:Data Stores 唯一遇到问题的脚本是没有理由的短脚本:

【问题讨论】:

    标签: macos lua roblox


    【解决方案1】:

    LocalScript 中的语法因等待而有点偏离。有了这个固定,它每次都有效。另外,我会使用事件处理程序而不是使用循环更新值:

    game.Players.LocalPlayer:WaitForChild("Data"):WaitForChild("Bells").Changed:Connect(function(value)
        script.Parent.TextLabel.Text = value
    end)
    

    【讨论】:

    • 输出(有时):堆栈开始脚本'Players.bryan99354.PlayerGUI.BellsGUI.LocalScript',第1行堆栈结束
    • 我无法重现您的问题。如果您在输出窗格中向上滚动,“堆栈开始”上方的行中显示的是什么?
    • 它说:11:33:04.906 - SliceCenter ((499.000000,112.000000), (501.000000,113.000000)) 超出了 imageOffset ((492.000000,112.000000), (493.0000), (493.0000), (493.0000) 的范围。对于 GuiImage[CoreGui.TopBar.TopBarFrame.RightFrame.MoreMenu.MoreMenuContainer.OverlayContextualMenu.PositionFrame.BaseMenu.ClippingFrame.ScrollingFrame.cell 2]
    • 11:33:04.907 - SliceCenter ((507.000000,112.000000), (509.000000,113.000000)) 超出了 imageOffset 的范围 ((500.000000,112.000000), (5301.0000000) 为 Gui CoreGui.TopBar.TopBarFrame.RightFrame.MoreMenu.MoreMenuContainer.OverlayContextualMenu.PositionFrame.BaseMenu.ClippingFrame.ScrollingFrame.cell 2.StateOverlay] 11:33:09.846 - 'Players.bryan99354:WaitForChild("Data")'
    • 但那是 Roblox 的 GUI
    猜你喜欢
    • 2021-05-24
    • 2020-08-26
    • 1970-01-01
    • 1970-01-01
    • 2018-06-09
    • 1970-01-01
    • 1970-01-01
    • 2015-10-29
    • 1970-01-01
    相关资源
    最近更新 更多