Hello. I've been scripting a simple Blood Gui that targets the player and checks their Health, and then changes the blood transparency based on their health. The only problem is that I don't know how to target a Humanoid like this. What I've been doing is this:
Humanoid = script.Parent.Parent.Parent.Parent.Character.Humanoid
That hasn't been working though. It should be simple for you guys, but I'm sure I didn't learn Lua like the average person.
It's probably because you're not waiting for your character to load. In a LocalScript, in your StarterGui, you could use something like this:
local player = game:service('Players').LocalPlayer local char = player:WaitForChild("Character") local humanoid = char:WaitForChild("Humanoid") if player then print("Player found") end if char then print("Character found") end if humanoid then print("Humanoid found") end
LocalScripts are handy this way, but :WaitForChild() is the key here.
How about instead of;
Humanoid = script.Parent.Parent.Parent.Parent.Character.Humanoid
Try;
repeat wait(0)until game:FindService("Players")and game.Players.LocalPlayer and game.Players.LocalPlayer.Character and game.Players.LocalPlayer.Character:FindFirstChild("Humanoid") --Repeats waiting until finds Players, LocalPlayer, LocalPlayer's Character, and LocalPlayer's Characrer's Humanoid local Plr = game.Players.LocalPlayer --LocalPlayer local Char = Plr.Character --LocalPlayer's Character local Humanoid = Char.Humanoid --LocalPlayer's Character's Humanoid --Rest of Coding here
Hope this helped!
So something like this would work?
local Blood = script.Parent local Humanoid = script.Parent.Parent.Parent.Parent.Character.Humanoid local player = game:service('Players').LocalPlayer local char = player:WaitForChild("Character") local humanoid = char:WaitForChild("Humanoid") if player then print("Player found") end if char then print("Character found") end if humanoid then print("Humanoid found") end if Humanoid.Health == 100 then Blood.Visible = false elseif Humanoid.Health >= 80 < 100 then Blood.Visible = true Blood.BackgroundTransparency = 0.2 elseif Humanoid.Health >= 60 < 80 then Blood.Visible = true Blood.BackgroundTransparency = 0.4 elseif Humanoid.Health >= 40 < 60 then Blood.Visible = true Blood.BackgroundTransparency = 0.6 elseif Humanoid.Health >= 0 < 40 then Blood.Visible = true Blood.BackgroundTransparency = 0.8 else print("An error has occured with the Blood Gui script.") end