Hi. Thank you all for your replies.
What I’ve done is edited Douglas’s code to be like this:
local function MakeParticleFX(Folder, part, hitB)
local attachment = Instance.new("Attachment")
attachment.WorldPosition = hitB.Position
attachment.Parent = workspace.Terrain
local particle = ChooseRandomChild(Folder):Clone()
particle.Parent = attachment
particle:Emit(particle:WaitForChild("EmitCount").Value)
game:GetService("Debris"):AddItem(attachment, particle.Lifetime.Max) -- Automatically delete the particle effect after its maximum lifetime.
end
The code works fine for me, thankfully. It’s also linked up to a Client event.
game.ReplicatedStorage.GunsRoot.Events.particl.OnClientEvent:Connect(function(Part, hitB, Folder, realTool)
print("got event")
if realTool ~= nil then
local folderH = realTool:WaitForChild("BodyAttach"):FindFirstChild("HitEffects")
if folderH then
if folderH:FindFirstChild(Folder) then
local FReal = folderH:WaitForChild(Folder)
MakeParticleFX(FReal, Part, hitB)
end
end
end
end)
server script:
-- Function for bullet hit effects
function ImpactEffects(Player, Folder, ImpactedPiece, ImpactedParent, realTool)
local mdl = ImpactedPiece:FindFirstAncestorWhichIsA("Model")
if not mdl or (mdl and not mdl:FindFirstChildOfClass("Humanoid")) then
if ImpactedPiece.Material == Enum.Material.Plastic then
particleEvent:FireClient(Player, ImpactedPiece, ImpactedParent, "Plastic", realTool)
end
end
end
Now, what’s wrong is that after the first shot, it keeps doubling up on the particle events. I’ve got a print command which tells me if I get the client event;
game.ReplicatedStorage.GunsRoot.Events.particl.OnClientEvent:Connect(function(Part, hitB, Folder, realTool)
print("got event")
if realTool ~= nil then
local folderH = realTool:WaitForChild("BodyAttach"):FindFirstChild("HitEffects")
if folderH then
if folderH:FindFirstChild(Folder) then
local FReal = folderH:WaitForChild(Folder)
MakeParticleFX(FReal, Part, hitB)
end
end
end
end)
I think, I’m not sure how, but the event is getting fired multiple times. Here is all my code for bullet handling, by the way.
function Fired(player, mousePos, origin, velocity, tool, bulletType, Dmg, HeadshotDmg, Module, FX)
local REQUIREDMODULE = require(Module)
if Dmg ~= REQUIREDMODULE.BaseDamage then
SecurityCheck(REQUIREDMODULE, Module)
end
CastParams.FilterDescendantsInstances = {player.Character, projrootWorkspace}
CastBehaviour.CosmeticBulletTemplate = projroot[bulletType]
CastBehaviour.MaxDistance = REQUIREDMODULE.Range
CastBehaviour.HighFidelityBehavior = FCModule.HighFidelityBehavior.Default
local function Fire(direc)
local dirCF = CFrame.new(Vector3.new(), direc)
local spreadDir = CFrame.fromOrientation(0, 0, math.random(0, math.pi * 2))
local spreadAng = CFrame.fromOrientation(math.rad(math.random(REQUIREDMODULE.SpreadMinimum, REQUIREDMODULE.SpreadMaximum)), 0, 0)
local dirFinal = (dirCF * spreadDir * spreadAng).LookVector
Caster:Fire(origin, dirFinal, velocity, CastBehaviour)
end
local POSNew = RayCastRays(mousePos, Module)
local dir = (POSNew - origin).Unit
for i = 1, REQUIREDMODULE.BulletsPerShot do
Fire(dir)
end
local function Impact(cast, result, velocity, bullet)
local HIT = result.Instance
local char = HIT:FindFirstAncestorWhichIsA("Model")
if char then
local targetHum = char:FindFirstChildOfClass("Humanoid")
if targetHum and (targetHum.Health > 0) then
local charPlayer = game.Players:GetPlayerFromCharacter(char)
if charPlayer then
if not char:FindFirstChild("creator") then
local crtag = Instance.new("ObjectValue")
crtag.Parent = char
crtag.Name = "creator"
crtag.Value = player
game:GetService("Debris"):AddItem(crtag, 2)
end
end
if DMGModule.CanDamage(char, player) then
--[[ if REQUIREDMODULE.DamageDropoffEnabled then
local DropoffRange =
end]]
if DMGModule.HeadshotDamage(char, HIT) then
targetHum:TakeDamage(HeadshotDmg)
else
targetHum:TakeDamage(Dmg)
end
end
elseif not targetHum then
end
else
end
ImpactEffects(player, FX, HIT, bullet, tool)
end
Caster.RayHit:Connect(Impact)
end
function lengthChanged(cast, lastPos, dir, length, v, bullet)
if bullet then
CastBehaviour.CosmeticlugerBullet = bullet
local bulletLength = bullet.Size.Z/2
local offSet = CFrame.new(0, 0, -(length - bulletLength))
bullet.CFrame = CFrame.lookAt(lastPos, (lastPos+dir)):ToWorldSpace(offSet)
game:GetService("Debris"):AddItem(bullet, 1.3)
end
end