Roblox LUA assumes tool instance is a string

folder.ToolActAsync.OnServerEvent:Connect(function(p, tool)
	if typeof(tool) ~= "Instance" then return end
	if p and p.Character and tool:FindFirstChild("Active").Value == true and p.Character:FindFirstChild(tool) then
		tool:FindFirstChild("Active").Value = false
		Simple.createAttackHitboxToTool(p.Character, tool, 1.1, 15, 0.37)
		delay((tool:FindFirstChild("CD").Value)-0.5, function()
			tool:FindFirstChild("Active").Value = true
			print("Finish")
		end)
	end
end)

Just because this check was added, it declared that the tool arg is a String??

p.Character:FindFirstChild(tool)

Why is this and how can I solve it?

image

2 Likes

It might be talking about the p argument too but I wasn’t sure because of how ROBLOX handles remote events (passing player regardless)

You need to do tool.Name because FindFirstChild returns an instance from a name. Also it didn’t declare tool arg as a string it just said the function requires a string.

1 Like

This needs to be:

and p.Character:FindFirstChild(tool.Name) then
2 Likes

You’re misinterpreting it.

It’s saying that it is expecting a string (for FindFirstChild), however the object you are providing is a tool.

1 Like

The problem lies in the third line. You are trying to use FindFirstChild with an instance as parameter, but you need to use a string. So you need to pass the tools name aka tool.Name.

1 Like

As you can see here, :FindFirstChild() requires the name of an instance to be searched for. E.G:

If you are looking for a tool called “foo”, you would do this

char:FindFirstChild(tool.Name) -- This will work if the tool is called "FOO"

However this will not work because you are providing the wrong type (you pass an instance albeit you need a string)

char:FindFirstChild(tool) -- Type error because you are passing an instance.

So please change
and p.Character:FindFirstChild(tool)

to:
and p.Character:FindFirstChild(tool.Name)