#healthbar for a nonhumanoid

27 messages · Page 1 of 1 (latest)

quick storm
#

how would I go about changing the size of this gui bar depending on the attribute of another part?

late citrus
#

like that but the script cant be in workspace, put it in starterplayerscripts. maybe consider using collectionservice since you'll probably have a lot of trees with healthbars

quick storm
#

gui doesnt move

#

the bar*

quick storm
#

i have been so stuck at this

#
local TweenService = game:GetService("TweenService")
local StarterGUI = game:GetService("StarterGui")

local bar = StarterGUI.ScreenGui.Frame.ImageLabel
local tree = workspace.Trees:WaitForChild("treeHitbox")
local health = tree:GetAttribute("Health")
local maxHealth = tree:GetAttribute('MaxHealth')

local Tween = TweenInfo.new(0.25, Enum.EasingStyle.Sine, Enum.EasingDirection.In, 0, false)

tree.AttributeChanged:Connect(function()
    -- create a new attribute 
    health = tree:GetAttribute("Health")
    local newSize = UDim2.new(health / maxHealth, 0, 1, 0)
    local tween = TweenService:Create(bar, Tween, {Size = newSize})
    tween:Play()
end)
#

ignore the comment

twilit fable
#

whats the problem

twilit fable
twilit fable
#

when a player joins the ui from startergui gets cloned into player.PlayerGui

#

edit that instead

quick storm
#

AIGHT

#

though the gui still WONT move

#

is this a gui problem

#

oh heck yeah

#

i put the script in my tool lol

quick storm
#

collectionservice?

#

how do i independently run the health bar on like each tree in the folder

quick storm
#

hello, new problem

#
-- play an animation on activation of the tool
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local PlayerGUi = game.Players.LocalPlayer.PlayerGui
local ScreenGui = PlayerGUi:WaitForChild("ScreenGui")

local character = game.Players.LocalPlayer.Character
local humanoid = character:FindFirstChild("Humanoid")
local rootPart = character:FindFirstChild("HumanoidRootPart")

local treeRemote = ReplicatedStorage.Remotes:FindFirstChild("TreeBreak")

for _, tree in workspace.Trees:GetChildren() do
    local distance = (rootPart.Position - tree.Position).Magnitude

    local bar = ScreenGui.Frame.ImageLabel
    local health = tree:GetAttribute("Health")
    local tool = script.Parent
    local effect = tool.Handle.effects.STRIKES
    local animation = tool.animate

    local damage = 5
    local maxHealth = 100
    local debounce = false
    
    ScreenGui.Enabled = true
    
    -- animation of the tool
    tool.Activated:Connect(function()
        if debounce then return end
        debounce = true

        local animationTrack = humanoid:LoadAnimation(animation)
        animationTrack:Play()
        animationTrack.Stopped:Wait()
        effect:Emit(1)

        task.wait()
        debounce = false

        health = tree:SetAttribute("Health", health - damage)
    end)
    --------------------------------------------------
    task.wait(0.5)
    ----------------------
    tree.AttributeChanged:Connect(function()
        health = tree:GetAttribute("Health")
        print(health)
        treeRemote:FireServer(health)

        local Tween = TweenInfo.new(0.25, Enum.EasingStyle.Sine, Enum.EasingDirection.In, 0, false)    
        local newSize = UDim2.new(health / maxHealth, 0, 1, 0)
        local tween = TweenService:Create(bar, Tween, {Size = newSize})
        tween:Play()
    end) 
end
#

how would I go about with only changing the health if im in the hitbox or close enough?

#

and there are

#

errors I dont understand