local text = game.Workspace.Health_Teller.BillboardGui.health game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) local player_name = player.Name print(player_name) local player_hum = game.Workspace.player.name.Humanoid print(player_hum.Health) end) end)
To answer your question, you need to wrap your variable in [ ].
Here is the new code.
local text = game.Workspace.Health_Teller.BillboardGui.health game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) local player_name = player.Name print(player_name) local player_hum = game.Workspace[player_name].Humanoid print(player_hum.Health) end) end)
But there is a better way to do this. The CharacterAdded
event of Player
passes a reference to the character (That's what the character
argument in function(character)
is). The code that utilizes the character
argument is below.
local text = game.Workspace.Health_Teller.BillboardGui.health game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) print(player.Name) print(character:WaitForChild("Humanoid").Health) end) end)
I hope my answer could solve your problem! If it did please remember to mark it as correct!
local text = game.Workspace.Health_Teller.BillboardGui.health game.Players.PlayerAdded:connect(function(player) -- you dont need to add character added just say player.Character local player_name = player.Name print(player_name) local player_hum = game.Workspace:WaitForChild(player_name).Humanoid -- fixed print(player_hum.Health) --removed one end because you can just say player.Character end)