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

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

script.Parent.Throw.OnServerEvent:connect(function(player, mousePosition)
	if tool.Handle.Grenadee then
		tool.Handle.Grenadee:Play()
	end
	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)
