grenade = Instance.new("Tool") grenade.Parent = game.Players.meunumbertwo.Backpack grenade.GripPos = Vector3.new(0,0,0.20000000298023) grenade.Grip = CFrame.new(0,0,0.20000000298023) * CFrame.Angles(-0.0049994587898254, -0.46360263228416, -0.011179762892425) grenade.TextureId = "http://www.roblox.com/asset/?id=200845119" grenade.GripForward = Vector3.new(0.44717335700989,-0.004471733700484,-0.89443612098694) grenade.Name = "Grenade" grenade.GripRight = Vector3.new(0.89439141750336,-0.0089439144358039,0.44719570875168) grenade.GripUp = Vector3.new(0.0099995005875826,0.99994999170303,0) grenade.ToolTip = "KABOOM" handle = Instance.new("Part",grenade) handle.FormFactor = Enum.FormFactor.Custom handle.TopSurface = Enum.SurfaceType.Smooth handle.Size = Vector3.new(0.80000013113022,0.92000025510788,0.79999816417694) handle.Name = "Handle" handle.Locked = true handle.CFrame = CFrame.new(-25.705892562866,0.38461595773697,7.3462233543396) * CFrame.Angles(1.5769363641739, -0.0078776096925139, 2.243584394455) handle.BrickColor = BrickColor.new("Earth green") handle.Friction = 0.30000001192093 handle.BottomSurface = Enum.SurfaceType.Smooth mesh = Instance.new("SpecialMesh",handle) mesh.Scale = Vector3.new(1.2999999523163,1.5,1.2999999523163) mesh.MeshId = "http://www.roblox.com/asset/?id=166887416" mesh.MeshType = Enum.MeshType.FileMesh pin = Instance.new("Sound",handle) pin.Name = "Pin" pin.Volume = 1 pin.SoundId = "http://www.roblox.com/asset?id=168184001" boom = Instance.new("Sound",handle) boom.Name = "Boom" boom.Volume = 1 boom.SoundId = "rbxasset://sounds/collide.wav" boom.PlayOnRemove = true throwanimation = Instance.new("Animation",grenade) throwanimation.AnimationId = "http://www.roblox.com/Asset?ID=168160500" throwanimation.Name = "ThrowAnimation" configurations = Instance.new("Configuration",grenade) configurations.Name = "Configurations" cooldown = Instance.new("NumberValue",configurations) cooldown.Name = "Cooldown" cooldown.Value = 3 grenadevelocity = Instance.new("NumberValue",configurations) grenadevelocity.Name = "GrenadeVelocity" grenadevelocity.Value = 100 fusetime = Instance.new("NumberValue",configurations) fusetime.Name = "FuseTime" fusetime.Value = 5 explodeontouch = Instance.new("BoolValue",configurations) explodeontouch.Name = "ExplodeOnTouch" explodeontouch.Value = true explosionradius = Instance.new("NumberValue",configurations) explosionradius.Name = "ExplosionRadius" explosionradius.Value = 5 throw = Instance.new("RemoteEvent",grenade) throw.Name = "Throw" local player = game.Players.LocalPlayer local mouse = player:GetMouse() local tool = grenade local config = tool:WaitForChild("Configurations") local canThrow = true tool.Equipped:connect(function() mouse.Icon = "rbxasset://textures/GunCursor.png" end) tool.Unequipped:connect(function() mouse.Icon = "" end) tool.Activated:connect(function() if canThrow then canThrow = false local throwAnimation = player.Character.Humanoid:LoadAnimation(tool.ThrowAnimation) throwAnimation:Play() -- Load and play the throwing animation throwAnimation.KeyframeReached:connect(function(keyframe) -- Wait 'til we reach a keyframe if keyframe == "tick" then -- if the keyframe is 'tick' then play the pin sound tool.Handle.Pin:Play() elseif keyframe == "throw" then -- otherwise, if it's 'throw,' tell the serverscript to throw our grenade tool.Throw:FireServer(mouse.Hit.p) throwAnimation:Stop() mouse.Icon = "rbxasset://textures/GunWaitCursor.png" end end) wait(config.Cooldown.Value) mouse.Icon = "rbxasset://textures/GunCursor.png" canThrow = true end end) grenade.Activated:connect(onActivated) local tool = grenade local config = tool:WaitForChild("Configurations") function AngleOfReach(distance, altitude, velocity) local theta = math.atan((velocity^2 + math.sqrt(velocity^4 -196.2*(196.2*distance^2 + 2*altitude*velocity^2)))/(196.2*distance)) if theta ~= theta then theta = math.pi/4 end return(theta) end function Explode(part) local explosion = Instance.new("Explosion", workspace) explosion.Position = part.Position explosion.BlastRadius = config.ExplosionRadius.Value part:Destroy() end grenade.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)