How can I detach a tool from a character's grip?

I’m scripting a throwing weapon, how can I detach the tool from the player’s grip when the weapon is thrown?

1 Like

Does the weapon work like a job Grenade

https://www.roblox.com/library/200848629/Grenade

I’m scripting thor’s hammer, and I’m working on the throwing aspect of it.

Use the same sequence and style as the tutorial Grenade

Handle.Transparency = 1

Copy the hammer and shoot it towards the target

Handle.Transparency = 0

Try writing the code and if it doesn’t work properly then share the code here and ask for help

I apologize for the writing style, as I do not speak English

Hey man, I’m having trouble with this line:

MjolnirClone.Velocity = (CFrame.new(MjolnirClone.Position,Vector3.new(MousePosition.X, MousePosition.Y, MousePosition.Z)) * CFrame.Angles(0,0,0).LookVector * 300)

If you want to throw the hammer straight for a long distance

You must use another formula

use BodyVelocity

Oh, but the error I got with that specific line is this "ServerScriptService.Mjolnir Attacks:24: attempt to index nil with ‘X’ "

Some guy advised me to use

MjolnirClone.BodyVelocity = CFrame.new(MjolnirClone.Position, MousePosition).LookVector*300

but even that errors:""ServerScriptService.Mjolnir Attacks:24: invalid argument #2 to ‘new’ (Vector3 expected, got nil)

So I tweaked the line to

MjolnirClone.BodyVelocity = CFrame.new(MjolnirClone.Position,Vector3.new(MousePosition)).LookVector * 300

And now a new error has come up:“BodyVelocity is not a valid member of Part “Workspace.Handle””

If you want to get the tool Thor’s hammer in the video clip

If you want everything to work properly

Put everything in its place according to the image

Use the same names and don’t change anything

Tool

This code when placed inside a LocalScript

local HammerEvent = script.Parent:WaitForChild("HammerEvent")
local tool = script.Parent
tool.Equipped:Connect(function(mouse)
mouse.Button1Down:Connect(function()
local Location = mouse.Hit.p
HammerEvent:FireServer(Location)
end)
end)

This code when placed inside a Script

local HammerEvent = script.Parent:WaitForChild("HammerEvent")
local Handle = script.Parent:WaitForChild("Handle")
local ServerStorage = game:GetService("ServerStorage")
local Hammer = ServerStorage:WaitForChild("Hammer")
local Enable = true

local function onHammerFired(player, Location)
--print(player, Location)	
if Enable == true then
Enable = false	
		
	local ray = Ray.new(Handle.CFrame.p, (Location - Handle.CFrame.p).unit * 300)
	local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)
	
	local distance = (Handle.CFrame.p - position).magnitude
	
	Handle.Transparency = 1
	
	local CopieHammer = Hammer:Clone()
	CopieHammer.CanCollide = false
	CopieHammer.CFrame = CFrame.new(Handle.CFrame.p, position) * CFrame.Angles(math.rad(-90), 0, 0)
	CopieHammer.Parent = game.Workspace
	
    local bodyvelocity = Instance.new("BodyVelocity")
    bodyvelocity.maxForce = Vector3.new(math.huge, math.huge, math.huge)
    bodyvelocity.velocity = CFrame.new(Handle.CFrame.p, Location).lookVector * 100	
	bodyvelocity.Parent = CopieHammer	
		
	spawn(function()	
	CopieHammer.Touched:connect(function(hit)
	if hit.Parent.Name ~= player.Name then			
	local humanoid = hit.Parent:FindFirstChild("Humanoid")		
	if humanoid then		
		humanoid:TakeDamage(30)	
		CopieHammer:Destroy()		
		wait(2)			
		Handle.Transparency = 0		
		Enable = true			
	end			
	end			
	end)		
	end)
	wait(3)			
	CopieHammer:Destroy()				
	Handle.Transparency = 0					
	Enable = true
end
end

HammerEvent.OnServerEvent:Connect(onHammerFired)

If it doesn’t work well then tell me about the problem

I wish you good luck in what you want to do

Sorry for the late reply, but the hammer just shoots up from the baseplate as opposed to my character’s hand and I wrote the script word for word.

If the hammer model you are using consists of several parts

As in the picture

Model

You have to add the following

local HammerModel = ServerStorage:WaitForChild("HammerModel") -- Add the model name

	local CopieHammer = HammerModel:Clone()
	local CopieCenter = CopieHammer:FindFirstChild("Center")	
	if CopieCenter then
	CopieHammer.PrimaryPart = CopieCenter 	
	local NewCopieHammerCFrame = CFrame.new(Handle.CFrame.p, position) * CFrame.Angles(math.rad(-90), 0, 0)
	CopieHammer:SetPrimaryPartCFrame(NewCopieHammerCFrame)

bodyvelocity.Parent = CopieCenter

Delete and add everything according to its place in the above program

If the hammer you are using consists of only one Part, you should review the following

This determines the location to which the copy is transferred

CopieHammer.CFrame = CFrame.new(Handle.CFrame.p, position) * CFrame.Angles(math.rad(-90), 0, 0)

If not everything you mentioned is related to the problem, you should post more details about the problem here

This is a video clip using the same program with the variation I mentioned, and the hammer model is made up of several parts like the picture

It actually consists of just one part and a mesh. Would that still work?

You could just weld the hammer to the handle and then move the handle using part velocity or bodyvelocities.

Thor’s hammer Tool

This file is complete and works fine

Thor’s Hammer Tool.rbxl (26.6 KB)

1 Like

Thank you bro, you’ve gone above and beyond to help me. I really appreciate it.

1 Like

You’re welcome

I’m glad I was able to help you