Number sequence trouble

Hey Roblox devs. I’m trying to make a muzzle particle emitter show while the player is shooting a gun. I’m using a transparency number sequence to make the particle emitter show and hide. The thing is, I don’t have much experience with coding number sequences.

So, when the player first equips the gun and shoots it, the muzzle shows and hides like it’s supposed to. But, the second time the player shoots the gun it stays transparent.

			Muzzle.Transparency = NumberSequence.new{
				NumberSequenceKeypoint.new(0,1),
				NumberSequenceKeypoint.new(1,1),
			}

this is what hides the muzzle


		Muzzle.Transparency = NumberSequence.new{
			NumberSequenceKeypoint.new(0,0),
			NumberSequenceKeypoint.new(1,0),
		}

this is what makes it show.

I have a system that knows wether the player is shooting the gun or not which does work (I know because I’ve done countless prints to make sure my code is working), so I’m thinking I just made a mistake with the number sequence.

If you know anything about number sequences, any help would be appreciated.

1 Like

Looks like you are entering the numbers correctly, but what about the rest of the script?
It may not be getting set because the script isn’t getting to that section.
You could try printing variables in sections of script to see what their values/booleans are to troubleshoot your code, or post the entire section of the script that deals with the gun firing.

1 Like

Local Script:

local player = game.Players.LocalPlayer
local tool = script.Parent.Parent.Parent
local MuzzleEvent = player:WaitForChild("gunEvents").Muzzle
local equippedStatus = false

tool.Equipped:Connect(function()
	print("equipped")
	equippedStatus = true
	local Muzzle = player.Character.Blackout.Preview.MuzzleEffect
	while equippedStatus == true do
		wait(0.025)
		Muzzle.Texture = "rbxassetid://421803006"
		wait(0.05)
		Muzzle.Texture = "rbxassetid://421803091"
		wait(0.025)
		Muzzle.Texture = "rbxassetid://421803134"
		
		if player.Character.Blackout.ShootingStatus.Value == true then
			MuzzleEvent:FireServer()
		end

		if player.Character.Blackout.ShootingStatus.Value == false then
			Muzzle.Transparency = NumberSequence.new{
				NumberSequenceKeypoint.new(0,1),
				NumberSequenceKeypoint.new(1,1),
			}
		end
		wait()
	end
end)

while true do
	if equippedStatus == true and not player.Character:FindFirstChild("Blackout") then
		equippedStatus = false
	end
	wait()
end

The “equipped status” variable works, I printed it out, I just didn’t include it in this version of the script. The “shooting status” also works, but I don’t have it included. It’s a seperate script, but I know for a fact that’s not the problem. I could show you that script if you want but it would probably be a waste of time

Server Script:

game.Players.PlayerAdded:Connect(function(player)
	local MuzzleEvent = player:WaitForChild("gunEvents").Muzzle
	
	MuzzleEvent.OnServerEvent:Connect(function(Player)
		print("recieved muzzle event")
		local Muzzle = Player.Character.Blackout.Preview.MuzzleEffect
		
		Muzzle.Transparency = NumberSequence.new{
			NumberSequenceKeypoint.new(0,0),
			NumberSequenceKeypoint.new(1,0),
		}
	end)
end)
1 Like

Hi there, I’m not sure about NumberSequences but I do have a possible alternative if you’re using particle emitter;

ParticleEmitters have a neat little function called “Emit”, which allows you to generate a controlled number of particles, even when it’s not enabled.

So when you shoot, you would use:

Muzzle:Emit(number)--layer it up a bit by choosing how many particles to emit

And assuming your particle is a quick flash, you won’t need to do any cleanup, just Emit every time the gun shoots.

1 Like

so should I keep it on transparent, then when the player shoots I emit it?

1 Like

I fixed the problem.

aksdfjugasoilkkudgalisdgfuioahs

1 Like

Please note how you solved it so others reading this ‘solved’ post can get help here.

3 Likes

Thank you for reminding me.

I was missing a remote event whenever the player stopped shooting the gun, so I was basically making the muzzle transparent through a local script which didn’t work. I recieved both the gunEquip event and the gunNotEquip events in the same server script, like this:

game.Players.PlayerAdded:Connect(function(player) -- this is for getting an instance (folder) that every player in the game starts with
     local MuzzleEvent = player:WaitForChild(gunEvents).MuzzleEvent -- "gunEvents" is the instance
     local MuzzleStopEvent = player:WaitForChild(gunEvents).MuzzleStopEvent

     MuzzleEvent.OnServerEvent:Connect(function(Player)
          local Muzzle = Player.Character.Blackout.Preview.MuzzleEffect -- makes the muzzle appear
          Muzzle.Transparency = NumberSequence.new{
               NumberSequenceKeypoint.new(0,0),
               NumberSequenceKeypoint.new(1,0),
		  }
     end)

     MuzzleStopEvent.OnServerEvent:Connect(function(Player)
          local Muzzle = Player.Character.Blackout.Preview.MuzzleEffect -- makes the muzzle disappear
		  Muzzle.Transparency = NumberSequence.new{
			  NumberSequenceKeypoint.new(0,1),
			  NumberSequenceKeypoint.new(1,1),
		  }
     end)
end)
2 Likes