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.

01--//LOCALSCRIPT
02 
03--//Variables
04local plr = game.Players.LocalPlayer
05local chr = plr.Character
06local hum = chr.Humanoid
07local bar = script.Parent.Parent
08local hbar = script.Parent
09local htxt = script.Parent.TextLabel
10repeat wait() until plr.chr
11local healthMath = hum.Health / (hum.MaxHealth)
12local replicatedStorage = game:GetService("ReplicatedStorage")
13local healthEvent = replicatedStorage.healthEvent
14 
15--//Booleans
View all 21 lines...
01--//SCRIPT
02 
03--// Variables
04local replicatedStorage = game:GetService("ReplicatedStorage")
05local healthEvent = replicatedStorage.healthEvent
06 
07--// Scripting
08 
09local function onHealthChanged(player)
10    local hum = player.Character:WaitForChild("Humanoid")
11    local healthMath = hum.Health / (hum.MaxHealth)
12    local hBar = player.PlayerGui.healthAssets.healthBar
13    hBar:TweenSize(UDim.new(healthMath, 0, 1, 0), "Out", "Sine", .2)
14end

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.

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

Answer this question