Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is the x scale size for GUI not updating in my script?

Asked by 3 years ago

Here is the code I'm dividing the stone's health by its max health to get a scale size for the width of the frame

Here is the code, not sure what's wrong here everything looks okay.

local hitPart = script.Parent
local attack = game:GetService("ReplicatedStorage"):WaitForChild("Attack")
local player = game:GetService("Players").LocalPlayer
local itemHealth = player:WaitForChild("PlayerGui"):WaitForChild("ItemHealth")

local debounce = false

hitPart.Touched:Connect(function(part)
    if debounce == false then
        debounce = true

        if part.Name == "Stone" then
            itemHealth.Background.Bar.Size = UDim2.fromScale((part.Health.Value / part.MaxHealth.Value), 0)
            print((part.Health.Value / part.MaxHealth.Value))
            itemHealth.Background.ProgressText.Text = tostring(part.Health.Value).."/"..tostring(part.MaxHealth.Value)
            itemHealth.Background.Title.Text = part.Name
        end

        player:WaitForChild("AttackTimeout").Value = 10
        attack:FireServer(player, part)

        wait(.5)
        debounce = false
    end
end)

Answer this question