Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is there a good way to add spread to my spell?

this attack/spell is a shotgun-esk attack in which a barrage of 6 bullets hits an enemy. But it doesn't spread like a normal shotgun. Is there a good way to add spread to my spell?

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local Mouse = Player:GetMouse()
Enabled = true

Mouse.KeyDown:connect(function(key)
	if Enabled == false then return end
	key = key:lower()
	if key == 'r' then
		Enabled = false
		
		for i=1,6 do
		--Fire Ball Projectile
		local FireBall = Instance.new('Part')
		FireBall.Shape = 'Ball'
		FireBall.Name = "FireBall"
		FireBall.Material = 'Neon'
		FireBall.BrickColor = BrickColor.new('Dark orange')
		FireBall.Parent = Character.ProjectileStorage
		FireBall.CFrame = Character.Torso.CFrame*CFrame.new(0,0,-1.5)
		FireBall.Size = Vector3.new(1,1,1)
		FireBall.Transparency = 0.1
		FireBall.CanCollide = false
		
		--Sound Effects
		local Fire2 = script:WaitForChild('Fire2')
		
		local BV = Instance.new('BodyVelocity')
		BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
		BV.Velocity = Character.Torso.CFrame.lookVector*50
		BV.Parent = FireBall
		local Dmg = script:WaitForChild('FireDamage'):Clone()
		Dmg.Parent = FireBall
		Dmg.Disabled = false
		
		Fire2:play()
		
		--Particles
		local FireParticle1 = script:WaitForChild('ParticleEmitter'):Clone()
		FireParticle1.Parent = FireBall
		
		FireBall:clone()

		wait(0.1)
		
		--FireBall Destroy
		local Disapper = script:WaitForChild("Disappear"):Clone()
		Disapper.Parent = FireBall
		Disapper.Disabled = false
		
		end
		
		wait(3)
		Enabled = true
	end
end)

4 comments

0

I also used a for loop, so whoever got upset at me, are you happy now?

0

Thats not what I meant.

0

keybaord input of that method is deprecated use this : http://wiki.roblox.com/index.php?title=Keyboard_input

0

add random rotation to them

1 answer

✓ Accepted answer

You would want to add a random factor to the velocity:

local spread = 5 -- Try changing this to suit your needs
BV.Velocity = Character.Torso.CFrame.lookVector*50 + Vector3.new(
	spread*math.random()*2 - spread,
	spread*math.random()*2 - spread,
	spread*math.random()*2 - spread)
-- Adds -5 to 5 units of velocity on each axis randomly

Also, make sure you initialize your randomizer with proper entropy by placing this at the start or end of the script:

math.randomseed(tick())

3 comments

0

YEa

0

thanks

0

I have improved my answer since you last commented. The code now allows the random spread number to be any number in the range instead of just whole numbers.

This discussion is preserved as it was. New answers, comments, and votes are closed.