hey, so as i said in my last post, i have a lot of bugs in my game that i have no idea how to fix them, i tried so many ways to fix it but nothing worked. i’m not a good Scripter already telling…
to make it clear, i have a RPG game that every level it gives you 4 max hp, the starting hp (level 1) is 20, so i made a formula , LEVEL*4+16
in the script i named my Level as LOVE , so Level = LOVE
and now im testing my hp bar when i’m level 100
so my bug is:
https://gyazo.com/4c966fbe69996c9f5171b38b501b6fe3
basically , sometimes i start with 20 maxhp while i suppose to start with 416, because the formula [100*4+16], but only after i die it changes to 416… and that’s not all
second bug with hp bar:
https://gyazo.com/d36348827934603b778fdb89f131271b
[it’s recorded after i died once already]
so yea, as you can see the hp won’t go down in the UI, but it still kills you…
my hp bar script script:
local remote = game.ReplicatedStorage.PlayerSpawned
local player = game.Players.LocalPlayer
local human = player.Character:WaitForChild("Humanoid")
wait(1)
script.Parent.Frame:TweenSize(UDim2.new(100/100,0,1,0), "Out", "Quad", .25)
script.Parent.TextLabel.Text = (human.Health .. "/" .. human.MaxHealth)
human.HealthChanged:Connect(function(nh)
local human = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
local newHealth = player.Character.Humanoid.Health
local maxhp = human.MaxHealth
if maxhp then
spawn (function()
script.Parent.Frame:TweenSize(UDim2.new(newHealth/player.Character.Humanoid.MaxHealth,0,1,0), "Out", "Quad", .25)
end)
end
script.Parent.TextLabel.Text = math.floor(newHealth+0.5) .. "/" .. maxhp
end)
remote.OnClientEvent:Connect(function()
local human = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
script.Parent.Frame:TweenSize(UDim2.new(100/100,0,1,0), "Out", "Quad", .25)
script.Parent.TextLabel.Text = (human.Health .. "/" .. human.MaxHealth)
end)
the hp changes from a script in ServerScriptService:
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
wait()
char.Humanoid.MaxHealth = plr.GasterVoid.LOVE.Value*4 + 16
char.Humanoid.Health = char.Humanoid.MaxHealth
game.ReplicatedStorage.PlayerSpawned:FireClient(plr)
end)
end)
here’s where everything placed and all:
the first script placed in LocalScript in HPbar frame
and the second script placed in ServerScriptService in MAX_HP
hope it was clear and understandable, thanks in advance