Infinite yield happening though the object is there

Error on line 17, Code:

local serverStorage = game:GetService("ServerStorage")
local replicatedStorage = game:GetService("ReplicatedStorage")

local modules = serverStorage:WaitForChild("Modules")
local mhb = require(modules:WaitForChild("HitBox"))

local remotes = replicatedStorage:WaitForChild("Remotes")
local events = remotes:WaitForChild("Events")
local eventsBat = events:WaitForChild("Bat")

local swingBat = eventsBat:WaitForChild("SwingBat")

swingBat.OnServerEvent:Connect(function(player)
	local character = player.Character or player.CharacterAdded:Wait()
	
	local bat = character:WaitForChild("bat")
	local hbTarget = bat:WaitForChild("hitboxhere")

	local hb = mhb(hbTarget)

	spawn(function()
		wait(1)
		hb:Destroy()
	end)

	hb.Touched:Connect(function(hit)
		hb:Destroy()

		local character = hit.Parent
		local characterHumanoid = character:WaitForChild("Humanoid")
		local characterRoot = character:WaitForChild("HumanoidRootPart")

		characterHumanoid:TakeDamage(10)
	end)
end)

Yes, I know spawn is bad practice but coroutine.wrap won’t wont for me.

coroutine.wrap(function() end)() This is how you use coroutine.wrap(). You need to make sure you add the extra () at the end.

Thanks!

limit
limit

are you sure you’re part named "hitboxhere" is Archivable? If it isn’t, the problem is that it won’t show up in scripts, therefore meaning a infinite yield (because you did WaitForChild)

It says Archivable is true, but still doesn’t work.

Are you really sure it’s there? Try checking your character > bat in serverside perspective to see if it is visible to the server.

I checked in studio.

limit
limit

Is “hitboxhere” created on a localscript or a serverscript, or does it come with the tool?

It’s not a tool, it’s manually welded, and hitboxhere is already in the bat model.

Is it welded on server or client?

What about directly referencing “hitboxhere”, does it appear as nil?

Just realized the problem, I named the model and the localscript the same.

1 Like