I'm making a script that assigns a NumberValue to the player that is equivalent to their health, however, it either says that the character is a nil value, or the humanoid/character is not a valid member of player. Any help?
function onPlayerAdded(player) local ValueFolder = Instance.new("Folder") ValueFolder.Parent = player ValueFolder.Name = "ValueFolder" local PlayerHealth = Instance.new("NumberValue") PlayerHealth.Parent = player.ValueFolder PlayerHealth.Name = "PlayerHealth" PlayerHealth.Value = player.Character.Humanoid.Health end game:GetService("Players").PlayerAdded:connect(onPlayerAdded)
Try waiting for the character to be added to the workspace, not when the player is added to the game.
.CharacterAdded:Connect(character)
and then use character:WaitForChild("Humanoid")
to wait for the humanoid
If this doesn't make sense, just ask.
Try this:
function onPlayerAdded(player) local ValueFolder = Instance.new("Folder") ValueFolder.Parent = player ValueFolder.Name = "ValueFolder" player.CharacterAdded:Connect(function(character) local PlayerHealth = Instance.new("NumberValue") PlayerHealth.Parent = player.ValueFolder PlayerHealth.Name = "PlayerHealth" PlayerHealth.Value = character:WaitForChild("Humanoid").Health end) end game:GetService("Players").PlayerAdded:connect(onPlayerAdded)
Hope this helped!