Infinite yield possible Error everytime I run the script

I need to get this script to fire an event but also create the event

I get the error: Infinite yield possible on ‘Players.Smixzol:WaitForChild(“Character”)’

I hava tried rewriting the code and playing with around with it still gives the same error all the time

local player = game.Players.LocalPlayer

if not player then
	return
end
local Character = player:WaitForChild("Character")
if not Character then
	return
end
print("foundplayer");
local playergetmouse = player:GetMouse();

if not player then
	return
end

local HumanoidRootPart = player.Character:WaitForChild("HumanoidRootPart")
if not HumanoidRootPart then
	return
end
print("Root part found");
local PunchEvent = Instance.new("RemoteEvent")
PunchEvent.Parent = player.Character;
if not PunchEvent then
	return
end
print("puncheventadded");

print("script on");

coroutine.wrap(function()
	while true do
		if playergetmouse.Button1Down then
	print("firing server");
	Character.PunchEvent:FireServer()
	print("fired server");

		end
	end
end)()


Character is not a child of a player object, rather it is a property which directs to the character model of the said player in workspace. So instead of doing WaitForChild, you should instead obtain the character directly if it exists and if it doesn’t use the CharacterAdded event to obtain it

local Character = player.Character or player.CharacterAdded:Wait()

Character isn’t a child of Player it is a value of it.

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