Raycast Hitbox Bugged when Tool is cloned

What I am trying to do
Hey there, I’m trying to create a shop system for my RPG game that I am making. The shop works well, except I have one problem with how it distributes the item the player bought.

The Issue
My issue is that one of the items that are sold, the sword, uses Raycast Hitbox V4 for dealing damage, however when the player buys the item the Raycasts get “stuck” in the air.

It looks like this:
(The shop npc is the character model with my roblox avatar)

image

I’ve tried debugging the issue, and I think the problem comes with the script that actually distributes the items. Not completely sure tho as I’m not too good at debugging.

Anyways here is the script (that actually distributes it):

game.ReplicatedStorage.BuyItem.OnServerEvent:Connect(function(player, from, toolName, price)
	player.leaderstats.Grams.Value -= price
	local toolCopy = game.ReplicatedStorage.Items:FindFirstChild(toolName):FindFirstChild(toolName):Clone()
	toolCopy:WaitForChild("Handle").Anchored = false
	toolCopy.Parent = player.Backpack
end)

Another thing I find weird is that I have another npc that gives out quests and gives the player a reward if they finish it. If I make it so they give the sword as a reward, the raycast hitboxes work for some reason. If you guys need any more context, like the script for interacting with the npc and others just tell me.

I’m not sure if I am just being dumb or something, but any help would be appreciated!

Is your hitbox well welded?
Are you raycasting the attacks from the client or the server in from a local script or a normal script?

I use Raycast Hitbox v4 for my hitboxes. I’m raycasting the attacks from the sword script using.

Are you requiring the module from a Client run context script?

I’m requiring the module in my sword script, which uses the legacy run context. I’ll try doing that.

(also if you want I can give you the code for my sword script)

HOLY! It worked, I can’t believe just a few clicks is what took me so long to do just to fix it. tysm.

Oh. I thought the script was already on Client and it was running in ReplicatedStorage. However, since it seems to work, you should check and make sure that your tool functions normally on the server. If not, you need to add a remote event to handle damage and all that.

Should the tool with the script on client be in replicated storage instead?

No, unless you want it to run there.

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