Why is tool not working after clone?

Hello,
yes ive looked for other peoples solutions and everything.
Ive searched multiple topics and various forums.
None of them worked and went to my almost last resort: AI
Also didnt work as excpected. My last resort: Making a topic

Whats my probem? Basically what the title says.

I have multiple modules, one of them clones the tool, parents it into a folder in serverstorage which works, and then throws it in the backpack of the player, i also tried putting it in the char of the plr with no succes.

A short video of 7 sec demonstrating the output and the outcome of the issue:
https://gyazo.com/529541c3edc83da200f81f96f6c0b4ca

The snippet of code which clones and throws it in the serverstorage:

function Handler.new(tool:Tool, hrp:Part)
	local model = Instance.new("Model")
	local char:Model = hrp.Parent
	local arm:Part = char:FindFirstChild("Right Arm")
	
	local self = setmetatable({}, Handler)
	self.max = tool:GetAttribute("Max")
	local clone = tool:Clone()
	clone.Parent = throwntools
	self.t = clone

Yes im 100% sure the tool exists and the hrp exists.
The serverscript which fires the Handler.new()

local remote = game.ReplicatedStorage.Remotes.ExtraMechanics.meleeThrow

local toolHandler = require(script.ToolHandler)

remote.OnServerEvent:Connect(function(plr, tool, dir)
	local char = plr.Character
	local hrp:Part = char.HumanoidRootPart
	
	if tool and dir and tool:GetAttribute("Melee") then
		local new = toolHandler.new(tool, hrp)
		new:Throw(dir, char)
	end
end)

When picking it up, this is when its putted in the backpack of the player using an proximity prompt:


function handler:PickUp()
	local prox:ProximityPrompt = self.p
	local tool:Tool = self.t
	local m:Model = self.m
	
	prox.Triggered:Connect(function(plr)
		local backpack = plr.Backpack
		tool.Parent = backpack
		m:Destroy()
	end)
end

I would appreciate concise explanation of whats happening and why its throwing errors. Error: 14:52:07.491 Players.emiliotigre2017.Backpack.IcePick.Server:19: attempt to index nil with 'OnHit' - Server - Server:19
What onHit? Well a function if a module im using called raycasthitbox V4

I am willing to share the script of the tool if asked.

Thanks for reading

1 Like

In the video it looks like the error actually occurs on line 17 in the pickuphandler script

Cant be possible. Why? My handler isnt called Server and doesnt have an function tha is onHit, so its the script inside the tool

It says that hitbox is not a valid member of model


? still exists dude?

I will share the serverscript inside of the tool:

local tool = script.Parent
local remote = tool:FindFirstChildWhichIsA("RemoteEvent")
local hitMod = require(game.ReplicatedStorage.Modules.RaycastHitboxV4)
local box = tool:WaitForChild("Hitbox")
local hitbox = hitMod.new(box)

local damage = nil

local function randomDmg()
	damage = math.random(8, 27)
end

--[[box.Changed:Connect(function(prop)
	if prop == "Parent" then
		hitbox = hitMod.new(box)
	end
end)]]

hitbox.OnHit:Connect(function(hit:Part, hum:Humanoid)
	randomDmg()
	if hum.Parent ~= tool.Parent then
		hum:TakeDamage(damage)
	end
end)

remote.OnServerEvent:Connect(function(plr)
	local char = plr.Character
	local hum = char.Humanoid
	local anim = hum:LoadAnimation(tool.Animations.toolSlash)
	anim:Play()
	hitbox:HitStart()
	task.wait(.6)
	hitbox:HitStop()
end)


the error from the video tells you

mhhh, might use a waitforchild, i will update you in a moment

Update: Removed error, the error above, so the OnHit is still there

well that onhit error is occurring because

either nothing was returned or the thing doesnโ€™t exist anymore from this

I have a solution i dont know how to make,
So my solution is to update the hitbox everytime the hitbox is changed, might work but i dont know.

Other thing i can try is not using the module :frowning:

Could you please show us the module?

Ray cast module? Thats an open source modulescript made by someone

Link: Raycast Hitbox 4.01: For all your melee needs!

Update: I will try making it without the module :frowning:
Update2: Works fine

1 Like

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