Infinite yield possible on 'char:WaitForChild("Head")'

Hello Everyone, i’ve been writing a script for a simple aura for practice purposes, and i got this error:

Here are the 2 scripts being utilized for this:

LocalScript, located in StarterPack:

local uIS = game:GetService("UserInputService")
local remoteevent = game.ReplicatedStorage:FindFirstChild("PlayAwakening")
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hrp = char:WaitForChild("HumanoidRootPart")
local awkAudio = game.ReplicatedStorage.Masamune.Audio:WaitForChild("Awk")
local module = require(script.CutsceneExecutionModule)
local cd = false
local cdtime = 36

uIS.InputBegan:Connect(function(input, isTyping)
	if not isTyping then
		if input.KeyCode == Enum.KeyCode.Z and cd == false then
			cd = true
			remoteevent:FireServer(plr, char)
			local awkAudioClone = awkAudio:Clone()
			--module:PlayFullCutscene(plr)
			awkAudioClone.Parent = hrp
			awkAudioClone:Play()
			print("event fired")
			task.wait(cdtime)
			cd = false
		end
	end
end)

and the server script, located in serverscriptservice:

local auras = game.ReplicatedStorage.Masamune:FindFirstChild("AwkAura")
local remoteevent = game.ReplicatedStorage:FindFirstChild("PlayAwakening")
local headaura = auras.Head:Clone()

remoteevent.OnServerEvent:Connect(function(plr, char)
	local playerhead = char:WaitForChild("Head")
	local headweld = Instance.new("WeldConstraint", playerhead)
	headaura.CFrame = playerhead.CFrame
	headaura.Parent = playerhead
	headweld.Part0 = playerhead
	headweld.Part1 = headaura
	
	local playerleftArm = char:FindFirstChild("Left Arm")
	local leftarmWeld = Instance.new("WeldConstraint")
end)

as you can see, the player’s character is being passed with a remotevent, i feel like it has something to do with that, not sure though, any help is appreciated.

2 Likes

You dont really need to pass the player’s character. You can simply do this:

remoteevent.OnServerEvent:Connect(function(plr)
	local playerhead = plr.Character:WaitForChild("Head")
	local headweld = Instance.new("WeldConstraint", playerhead)
	headaura.CFrame = playerhead.CFrame
	headaura.Parent = playerhead
	headweld.Part0 = playerhead
	headweld.Part1 = headaura
1 Like

it works, thank you! also if you don’t mind me asking why doesn’t the way i did work?

Im not really a good programmer myself so i cant really give a good answer.

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