For i, v won't find Player with value; attempt to index nil with 'WaitForChild'

So, i made this confusing poorly script, and I have no idea why :WaitForChild() isn’t finding Humanoid, and, why v isn’t Frog.Value

Frog.value is a string value who has the player name that will display they life at HealthGUI.
image

local hptext = script.Parent.LifePorcent

local Frog = game.ReplicatedStorage.GameVal.FrogName
local players = game.Players
local player 
local character

function FindFrog()
	for i, v in pairs(players:GetDescendants()) do
		print(v)
		if v.Name == Frog.Value then
			print(v)
			player = v
			character = v.Character

repeat wait() until player.Character
local connection_health
local connection_max_health
			
		end
	end
end
function Update()
	local humanoid = character:WaitForChild("Humanoid")
	bar:TweenSize(UDim2.new(humanoid.Health / humanoid.MaxHealth, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Back, .5, true)
	hptext.Text = humanoid.Health
end

function SetConnections()
	local humanoid = character:WaitForChild("Humanoid")
	connection_health = humanoid:GetPropertyChangedSignal("Health"):Connect(Update)
	connection_max_health = humanoid:GetPropertyChangedSignal("MaxHealth"):Connect(Update)	
	Update()
end

local localplayer = game.Players.LocalPlayer

localplayer.CharacterAdded:Connect(function(char)
    if player == Frog.Value then
	character = char
	if connection_health then connection_health:Disconnect() end
	if connection_max_health then connection_max_health:Disconnect() end
		SetConnections()
		end
end)

SetConnections()

codes messy but basically the character variable at the start isnt being assigned the character value before that line of code thats erroring runs so its trying to do character:waitforchild when character is still nil

thanks, lol, it was a useless function FindFrog() that I added.
image

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.