Roblox Studio / Lua 中的变量未更新

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

我正在尝试在 roblox studio 中制作一个系统,其中每当激活一个工具时,它都会播放动画并创建一个变量,该变量将是宝石的数量,然后该变量将被放入 PlayerGUI 中,但变量没有更新,一直停留在 1。这是我写的代码 -

local tool = script.Parent
local anim = tool:WaitForChild("1")
local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local loadanim = humanoid:LoadAnimation(anim)
local PlayerModule =       require(game.Players.LocalPlayer.PlayerScripts:WaitForChild("PlayerModule"))
local Controls = PlayerModule:GetControls()
local clicks = 0
local c = true
local confirm = false
local confirm2 = false
local confirm3 = false
local confirm4 = false
local GUI = player.PlayerGui.ScreenGui
local gems= GUI.TextLabel
local amount = 0
local times = false
local how = 0

tool.Activated:Connect(function ()
amount = amount + 1
gems.Text = tostring(amount)
loadanim:Play()
script.Disabled = true
Controls:Disable()
wait(1.5)
Controls:Enable()
wait(.2)
script.Disabled = false
clicks = 1
confirm = true
end)

供您参考 - 变量 Amount 是宝石的数量,变量 Gems 是 TextLabel,因此我可以更改文本。我还多次打印了变量,但它仍然显示“1”,因此 Gems TextLabel 没有问题。

我尝试创建另一个变量并将其更新为特殊值,因此只要宝石数量仍然为 1,即使激活两次,但它仍然不起作用。我不知道怎么办?!

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

local scriptDisabled
tool.Activated:Connect(function () if scriptDisabled then return end
amount = amount + 1
gems.Text = tostring(amount)
loadanim:Play()
scriptDisabled = true
Controls:Disable()
wait(1.5)
Controls:Enable()
wait(.2)
scriptDisabled = false
clicks = 1
confirm = true
end)

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