当我运行代码时,为什么我的生命值栏不工作(应该变成绿色并且生命值应该上升)?

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

我正在使用教程来制作 HP 杆,我按照它制作了一个 T 恤(我感觉),但我的 HP 不起作用。 这是参考教程.

这是代码

local greenFrame = script.Parent.Green
local label = script.Parent.TextLabel

local tweenService = game:GetService("TweenService")
local info = TweenInfo.new(.5,Enum.EasingStyle.Sine,Enum.EasingDirection.Out,0,false,0)

local lastHealth = 0

while wait(1) do
    if game.Players.LocalPlayer.Character then
        local currentHealth = math.floor(game.Player.LocalPlayer.Character.Humanoid.Health)
        
        local newFrameSize = UDim2.new(currentHealth/100,0,1,0)
        
        local tween = tweenService:Create(greenFrame,info,{Size=newFrameSize})
        
        tween:Play()
        
        if currentHealth > lastHealth then
            for i = lastHealth, currentHealth, 1 do
                label.Text = tostring(i).."Hp"
                wait(1/(currentHealth-lastHealth))
            end
        else
            for i = lastHealth, currentHealth, -1 do
                label.Text = tostring(i).."Hp"
                wait(1/(currentHealth-lastHealth))
            end
            
        end
        lastHealth = currentHealth
    end
end 
lua game-development roblox
1个回答
0
投票

您很可能有一些不应该大写的内容,反之亦然。

我建议暂时散布大量

print()
语句来查看所有值是什么,以便轻松判断哪里出了问题。

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