Throwing hammer is not working!

Hello there,
I’m making my own project and I doing superpower that you can throw the hammer
But when I press E it will play the animation and it will dont do anything, I tried to debug it and it printed all prints in script but in real nothing happens!

My script:

local remotes = game.ReplicatedStorage.ThrowHammerSuperpower

remotes.HaveSuperpower.OnServerInvoke = function(plr)
	if plr.ActualPower.Value == "ThrowHammer" then
		return true
	else
		return false
	end
end

remotes.Throw.OnServerEvent:Connect(function(plr)
	if plr.ActualPower.Value == "ThrowHammer" then
		local Load = plr.Character.Humanoid:LoadAnimation(game.ServerStorage.ThrowAnim)
		Load:Play()
		print("PlayedAnimation")
		wait(0.3)
		print("Continue Trough Wait")
		plr.Character.Hammer.Handle.Transparency = 1
		local NewHandle = plr.Character.Hammer.Handle:Clone()
		NewHandle.Parent = workspace
		NewHandle.CanCollide = true
		local Velocity = Instance.new("BodyVelocity",NewHandle)
		Velocity.Velocity = plr.Character.HumanoidRootPart.CFrame.lookVector * 50
		Velocity.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
		print("ThrowedHammer")
		local Connection 

		Connection = NewHandle.Touched:Connect(function(hit)
			local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
			if Player then
				print("DetectedPlayer")
				local Done = NewHandle.CFrame.lookVector * 40
				local Vel = Instance.new("BodyVelocity",Player.Character.HumanoidRootPart)
				Vel.Velocity = Done
				Vel.MaxForce = Vector3.new(500000,50000,500000)
				local Force = Instance.new("BodyForce",Player.Character.HumanoidRootPart)
				Force.Force = Vector3.new(50,25,50)
				game.Debris:AddItem(Vel,1)
				game.Debris:AddItem(Force,1)
				Player.Character.HumanoidRootPart.LastHit.Value = plr.Name
				plr.Character.Hammer.Handle.Transparency = 0
				NewHandle:Destroy()
				Connection:Disconnect()
			end
		end)
		print("Connected funcion")
		plr.Character.Hammer.Handle.Transparency = 0
		NewHandle:Destroy()
		Connection:Disconnect()
	else
		plr:Kick("Cheating")
	end
end)

Thanks for any help

2 Likes

Is your hammer anchored? Is it even parented to workspace?

1 Like

Your current code instantly destroys NewHandle after creating the Touched connection and at the same time it also makes plr.Character.Hammer.Handle visible again and disconnects the connection. That’s why nothing happens when the hammer is supposed to be thrown. I believe you could solve this by just adding a wait between creating the connection and doing the things after it.

-- earlier code...
print("Connected function")
wait(n)
plr.Character.Hammer.Handle.Transparency = 0
-- ... and the rest of the code

This isn’t related to the problem, but it’s not recommended to use Instance.new with parent argument.
https://devforum.roblox.com/t/psa-dont-use-instance-new-with-parent-argument/30296