I made a fireball attack and i need help trying to figure out a way so every time the player clicks the position the fireball spawns from wont be part.CFrame = Player.Character.Torso.CFrame * CFrame.new(0,0,-3) every time I tried tried using math.random but it only works whenever i respawn but i came up with this.

Lines 4 and 18-29.

Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()
Ammo = 1
Spray = math.random(1,5)

Mouse.Button1Down:Connect(function()
	if Ammo > 0 then
local	x = Instance.new("Part", workspace)
       	Ammo = Ammo -1
		x.Shape = "Ball"
		x.Size = Vector3.new(3,3,3)
		x.CanCollide = false
		x.BrickColor = BrickColor.new("Really red")
		x.Material = "Neon"
		x.TopSurface = "Smooth"
		x.BottomSurface = "Smooth"
		
	if Spray == 2 then 
			x.CFrame = Player.Character.Torso.CFrame * CFrame.new(1,1,-3)
			print("Spray2")
		end
		if Spray == 3 then
			x.CFrame = Player.Character.Torso.CFrame * CFrame.new(2,2,-3)
			print("Spray3")
		end
		if Spray == 4 then
			x.CFrame = Player.Character.Torso.CFrame * CFrame.new(1,5,-3)
			print("Spray4")
		end
		
		
		x.Touched:Connect(function(hit)
			if hit.Parent:FindFirstChild("Part") then
				x:Destroy()
			end --Part Destroy end
			
			if hit.Parent:FindFirstChild("Humanoid") ~= nil then
				hit.Parent.Humanoid:TakeDamage(12.5)
				x:Destroy()
			end --Humanoid Destory/Damage end
			
			
		end)--Touched end
		
local	v = Instance.new("BodyVelocity", x)
		v.Velocity = Player.Character.Torso.CFrame.lookVector * 500
		v.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
		
		if Ammo == 0 then
			wait(0.1)
			Ammo = 1
		end --Reload end
		
		wait(1.5)
		x:Destroy()
		
	end -- Ammo>0 end
	
end)--Button1Down end

also, i could only get Spray == 4 to work fine and Spray == 3 to work sometimes

5 comments

0

here'sa suggestion for the spray thing, try putting the spray inside of the mosuebuttondownscript

0

if you put the spray value on the outside of the mouse.button1down script, it will only randomize once, or it will randomize when the character respawns

0

Thank you, that fixed the randomizing problem. But for some reason it's bugging out sometimes and whenever i click it, it sometimes spawns the part in the middle (of the baseplate i think) and shoots of in the direction im facing, and it doesnt print out anything in output

0

hmm that's strange, i think you should test out the torso*cframe part of the script

0

I fixed the problem. i didnt have Spray == 1 and Spray == 5 occupied so when math.random equaled 1 or 5, it would shoot out of from the middle of the baseplate (maybe because thats the default position). Thank you so much for your help!