function Explode(y)local q=Instance.new("\069\120\112\108\111\115\105\111\110",workspace)q.Position=y.Position q.BlastRadius=config.ExplosionRadius.Value y:Destroy()end script.Parent.Throw.OnServerEvent:connect(function(y,q)local g=Vector3.new(tool.Handle.Position.X,0,tool.Handle.Position.Z)local J=Vector3.new(q.X,0,q.Z)local m=(g-J).magnitude local p=q.Y-tool.Handle.Position.Y local I=AngleOfReach(m,p,config.GrenadeVelocity.Value)tool.Handle.Transparency=1 local v=tool.Handle:Clone()v.Parent=workspace v.Transparency=0 v.CanCollide=true v.CFrame=tool.Handle.CFrame v.Velocity=(CFrame.new(v.Position,Vector3.new(q.X,v.Position.Y,q.Z))*CFrame.Angles(I,0,0)).lookVector*config.GrenadeVelocity.Value spawn(function()if config.ExplodeOnTouch.Value then v.Touched:connect(function(y)if y.Parent~=tool.Parent and y.CanCollide then Explode(v)end end)else wait(config.FuseTime.Value)Explode(v)end end)wait(config.Cooldown.Value)tool.Handle.Transparency=0 end)

function Explode(part)
	local explosion = Instance.new("Explosion", workspace)
	explosion.Position = part.Position
	explosion.BlastRadius = config.ExplosionRadius.Value
	part:Destroy()
end

script.Parent.Throw.OnServerEvent:connect(function(player, mousePosition)
	local handlePos = Vector3.new(tool.Handle.Position.X, 0, tool.Handle.Position.Z) -- remove Y from the equation, it's not needed
	local mousePos = Vector3.new(mousePosition.X, 0, mousePosition.Z) -- ditto
	local distance = (handlePos - mousePos).magnitude -- Get the distance between the handle and the mouse
	local altitude = mousePosition.Y - tool.Handle.Position.Y
	local angle = AngleOfReach(distance, altitude, config.GrenadeVelocity.Value) -- Calculate the angle
	
	tool.Handle.Transparency = 1
	local grenade = tool.Handle:Clone()
	grenade.Parent = workspace
	grenade.Transparency = 0
	grenade.CanCollide = true
	grenade.CFrame = tool.Handle.CFrame
	grenade.Velocity = (CFrame.new(grenade.Position, Vector3.new(mousePosition.X, grenade.Position.Y, mousePosition.Z)) * CFrame.Angles(angle, 0, 0)).lookVector * config.GrenadeVelocity.Value -- Throwing 'n stuff, it probably didn't need to be this long
	spawn(function()
	if config.ExplodeOnTouch.Value then
		grenade.Touched:connect(function(hit)
			if hit.Parent ~= tool.Parent and hit.CanCollide then -- Make sure what we're hitting is collidable
				Explode(grenade)
			end
		end)
	else
		
			wait(config.FuseTime.Value)
			Explode(grenade)
	end
	end)
	wait(config.Cooldown.Value)
	tool.Handle.Transparency = 0
end)
