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

HealthBar won't resize itself based on player's health, what's wrong?

Asked by 7 years ago

Please note that my game is Filtered Enabled and there is a remote event I'm using to apply changes.

P.S. There are no errors in output either.

--//LOCALSCRIPT

--//Variables
local plr = game.Players.LocalPlayer
local chr = plr.Character
local hum = chr.Humanoid
local bar = script.Parent.Parent
local hbar = script.Parent
local htxt = script.Parent.TextLabel
repeat wait() until plr.chr
local healthMath = hum.Health / (hum.MaxHealth)
local replicatedStorage = game:GetService("ReplicatedStorage")
local healthEvent = replicatedStorage.healthEvent

--//Booleans
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Health, false)

--//Scripting
plr.hum.HealthChanged:Connect(function(health)
    healthEvent:FireServer()
end)



--//SCRIPT

--// Variables
local replicatedStorage = game:GetService("ReplicatedStorage")
local healthEvent = replicatedStorage.healthEvent

--// Scripting

local function onHealthChanged(player)
    local hum = player.Character:WaitForChild("Humanoid")
    local healthMath = hum.Health / (hum.MaxHealth)
    local hBar = player.PlayerGui.healthAssets.healthBar
    hBar:TweenSize(UDim.new(healthMath, 0, 1, 0), "Out", "Sine", .2)
end

There are no errors in output either.

0
Server scripts can't handle client-sided stuff sadly. :/ You gotta use a `LocalScript` for that. TheeDeathCaster 2368 — 7y

1 answer

Log in to vote
0
Answered by
H4X0MSYT 536 Moderation Voter
7 years ago

Woah woah WOAH. Pretty sure you messed the order up. Why on earth does the server handle it? You can do all that in a local script with a few lines Simply change the size based on the players health. Player1 doesnt need to know what size Player 2's health gui is. Only the health. Not exploiter proof, people could exploit the gui, but that doesnt affect gameplay. This example is intended to work in a local script, inside Frame,2 which is inside Frame1. Frame 1 would be the background of the loading bar, Frame 1 being the loading bar.

while wait(1) do
    script.Parent.Size = Udim2.new(1, 0, game.Players.LocalPlayer.Character.Humanoid.Health/MaxHealth, 0)
end
Ad

Answer this question