Script doesn't work, I've been trying to make a healthbar reset script, so when they die it resets the gui.
if game.Players.LocalPlayer.Character.Humanoid.Health == 100 then script.Parent.Size = UDim2.new(1, 0, 0, 20) end
When the player resets, when they spawn back, the script won't run again, so when the player joins the game, it will run the script above and not run again.
Instead, you can use a loop:
while true do if game.Players.LocalPlayer.Character.Humanoid.Health == 100 then script.Parent.Size = UDim2.new(1, 0, 0, 20) end wait() end
or make the script run when the player respawns:
game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) if game.Players.LocalPlayer.Character.Humanoid.Health == 100 then script.Parent.Size = UDim2.new(1, 0, 0, 20) end) end) end)
The problem with your current code is that it will only run once, when the script initially runs. You want the resize to happen upon a certain thing, or certain event, occurring. That's what roblox has events for.
For this case, you're probably looking for either the Humanoid.Died
event or the Player.CharacterAdded
event. The latter would likely work best, since you presumably want the GUI to reset when the character respawns:
game.Players.LocalPlayer.CharacterAdded:Connect(function() script.Parent.Size = UDim2.new(1, 0, 0, 20); end)
Hope this helped.
P.S.: Not sure if this will be an issue for the way you have yours set up, but just in case, there's a member of ScreenGui
called ResetOnSpawn
. You're probably going to want that to be false. Cheers.