Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tool = script.Parent
- local remoteEvent = tool:WaitForChild("FireProjectile")
- remoteEvent.OnServerEvent:Connect(function(player, targetPosition)
- local character = player.Character
- if not character then return end
- local origin = character:FindFirstChild("Head") or character:FindFirstChild("HumanoidRootPart")
- if not origin then return end
- -- Create projectile
- local projectile = Instance.new("Part")
- projectile.Shape = Enum.PartType.Ball
- projectile.Size = Vector3.new(1, 1, 1)
- projectile.BrickColor = BrickColor.new("Bright red")
- projectile.Material = Enum.Material.Neon
- projectile.Anchored = false
- projectile.CanCollide = true
- projectile.Position = origin.Position + Vector3.new(0, 2, 0)
- projectile.Parent = workspace
- -- Launch it
- local direction = (targetPosition - projectile.Position).Unit
- local bodyVelocity = Instance.new("BodyVelocity")
- bodyVelocity.Velocity = direction * 100
- bodyVelocity.MaxForce = Vector3.new(1e5, 1e5, 1e5)
- bodyVelocity.Parent = projectile
- -- Damage on hit
- projectile.Touched:Connect(function(hit)
- if hit:IsDescendantOf(character) then return end -- Don't hit self
- local hum = hit.Parent:FindFirstChild("Humanoid")
- if hum then
- hum:TakeDamage(25)
- end
- projectile:Destroy()
- end)
- game.Debris:AddItem(projectile, 5)
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement