Endorsed Weapon Kit client side particles

I’m using Roblox’s endorsed weapon kit on a game, and I’ve made some pretty cool guns using it with some cool effects. The problem is that I recently noticed that all the particles the gun makes are client side, meaning other players wont visually see when you are using your weapon. It couldn’t find any built in work arounds for this to change though I could be wrong. Does anyone know if there is any work arounds for this, or if they have done this before, how they did this? This would mean a lot!

1 Like

You can either enable and disable the effects on a server script

or

You can try to do this:

On server (Only need one server script with such code because it is universal)

local RemoteEvent = Instance.new("RemoteEvent", game.ReplicatedStorage)
RemoteEvent.Name = "EffectUpdate"

RemoteEvent.OnServerEvent:Connect(function(...)

--The three dots means that all the variables will be compiled into a list such as: 
--VariableA, VariableB, VariableC
--In this case, it is: player, effect
    RemoteEvent:FireAllClients(...)
end)

On client

local Event = game.ReplicatedStorage:FindFirstChild("EffectUpdate")
if Event then
    --When you want to update an effect on other player's end
    local Effect = ("the effect you want to update on other player's side")
    Event:FireServer(Effect)
end

if Event then
    --Receive the update
    Event.OnClientEvent:Connect(function(Player_Responsible, Effect)
        Effect.Enabled = true
        wait()
        Effect.Enabled = false
    end)
end

Don’t just copy and paste as I am not confident about my grammar in these codes and they may not adapt to your explorer hierarchy perfectly.

Meanwhile you should also search up about ParticleEmitter:Emit() function, which is better.

1 Like

Thanks for the response dude. You were actually super quick, which is awesome. Unfortunately, I was looking for something more specific to the weapon kit. For documentation purposes, I’m going to post my fix. If anyone has does end up needing this specifically for whatever reason, and has any question, please hit me up. One other really important thing: when a player joins, it will replicate the other players shooting particles, only after the original player shoots. This is super important if you’re doing something PVP. For me though it’s perfectly fine.

Anyways, here it is. Find this in the BaseWeapon script

function BaseWeapon:onFired(firingPlayer, fireInfo, fromNetwork)
	if not IsServer then
		if firingPlayer == Players.LocalPlayer and fromNetwork then
			return
		end

		self:simulateFire(firingPlayer, fireInfo)
		
		
	else
		if self:useAmmo(1) <= 0 then
			return
		end
	end
end

and replace it with this (and make sure to read what all it’s doing, because there will be some things you might need to add or change):

--This function is contains all the right data to call self:simulateProjectile
function BaseWeapon:onFired(firingPlayer, fireInfo, fromNetwork)
	if not IsServer then
		if fromNetwork then
			return
		end
		
		--Essentialy, this function handles the particles for the other players
		game.ReplicatedStorage.Events.ToClient.GunFired.OnClientEvent:Connect(function(firingPlayer,firingSound,fireInfo,bulletEffect)
			if Players.LocalPlayer ~= firingPlayer then
				firingSound:Play()
				local numProjectiles = self:getConfigValue("NumProjectiles", 1)
				local randomGenerator = Random.new(self:getRandomSeedForId(fireInfo.id))
				for i = 1, numProjectiles do
					--make sure in the bulletWeaponScript, you replace the bulletEffect with this one if the player isn't the firing one
					self:simulateProjectile(firingPlayer, fireInfo, i, randomGenerator,bulletEffect)
				end
			end
			return
		end)
		
		--and this one handles the particles for the main player
		if Players.LocalPlayer == firingPlayer then
			self:simulateFire(firingPlayer, fireInfo)
		end

	else
		--[===[
		All of this below is the serverside code. 
		It consolidates the handling of a lot the work the other clients could do
		The amount of FindFirstChilds is probably not the best most efficient route, but it works.
		--]===]
		
		local character = workspace:FindFirstChild(firingPlayer.Name)
		if character then
			local tool = character:FindFirstChildOfClass("Tool")
			local RightHand = character:FindFirstChild("RightHand")
			if tool and RightHand then
				local firingSound = tool:FindFirstChild("Fired",true)
				if firingSound then
					firingPlayer.ThirdPersonParticlesEnabled.Value = true
					
					--Finds the data of where and what direction the firing client is shooting in
					local tipAttach = firingSound.Parent.TipAttachment
					local aimDir = -RightHand.CFrame.UpVector --  
					local tipCFrame = tipAttach.WorldCFrame
					local tipPos = tipCFrame.Position


					local fireInfo = {}
					fireInfo.origin = tipPos
					fireInfo.dir = aimDir
					fireInfo.charge = 0--Doesn't need charging effect on the server
					fireInfo.id = math.random(1,2^31-1)*math.random(1,2^31-1)
					
					--if you have multiple different bullet effects, this part is necessary
					--Otherwise, if another person is shooting, your client will read your client's bulleteffect, not theirs
					local bulletEffect = tool.Configuration:FindFirstChild("ShotEffect")
					if not bulletEffect then
						bulletEffect = "Bullet"
					else
						bulletEffect = bulletEffect.Value
					end
					bulletEffect = game.ReplicatedStorage.WeaponsSystem.Assets.Effects.Shots[bulletEffect]
					
					--sends off all the data to all the other clients to do the particles
					for _, plys in pairs(game.Players:GetChildren()) do
						local particlesEnabled =  plys.ThirdPersonParticlesEnabled.Value
						if plys.Name ~= firingPlayer.Name and particlesEnabled == true then
							game.ReplicatedStorage.Events.ToClient.GunFired:FireClient(plys,firingPlayer,firingSound,fireInfo,bulletEffect)
						end
					end


				end
			end
		end
		if self:useAmmo(1) <= 0 then
			return
		end
	end
end

Hope this helped!