I really need help with emitting the particle based on how much the player has clicks. I have been struggling with this for over 4 hours and still cant find a solution even to such an easy - one might say - task. Please help.
This is what shows up after activating the tool:
How it is stored:
Here is the code:
toolEvent.OnServerEvent:Connect(function(player)
local part
local att
local partEmmit
local char = player.Character or player.CharacterAdded:Wait()
local hrp = char:WaitForChild("HumanoidRootPart")
local clicks = player.leaderstats:WaitForChild("Strenght")
local function ToolName()
if char:FindFirstChild("Fire1") then
part = char.Fire1.Part:Clone()
elseif char:FindFirstChild("Fire2") then
part = char.Fire2.Part:Clone()
else
return
end
part.Parent = workspace.Stuff
part.Anchored = true -- Important so it stays in place
part.CanCollide = false -- No collision needed
part.Transparency = .5 -- Fully invisible Part
att = part:WaitForChild("Attachment")
partEmmit = att:WaitForChild("ParticleEmitter")
end
ToolName() -- <<< CALL THE FUNCTION here!!
local function emitterAmount()
local emmitAmount
if char:FindFirstChild("Fire1") and clicks.Value <= 50 then
emmitAmount = math.floor(clicks.Value / 2)
elseif char:FindFirstChild("Fire1") and clicks.Value > 50 then
emmitAmount = 25
end
if char:FindFirstChild("Fire2") and clicks.Value <= 100 then
emmitAmount = math.floor(clicks.Value / 4)
elseif char:FindFirstChild("Fire2") and clicks.Value > 100 then
emmitAmount = 25
end
if emmitAmount < 1 then
emmitAmount = 1
end
return emmitAmount
end
-- Create a new Attachment
local offset = hrp.CFrame.LookVector * 5
part.CFrame = hrp.CFrame + offset
local emitter = att:FindFirstChild("ParticleEmitter")
if emitter then
print("Emitter found: " .. emitter.Name)
emitter:Emit(emitterAmount()) -- Use the calculated emitter amount
print(emitterAmount(), "particles emitted!")
print("Clicks:", clicks.Value)
task.delay(0.5, function()
part:Destroy()
end)
else
warn("No ParticleEmitter found.")
end
end)
Review this code and try this one, see if it improves:
toolEvent.OnServerEvent:Connect(function(player)
local part, att, partEmmit
local char = player.Character or player.CharacterAdded:Wait()
local hrp = char:WaitForChild(“HumanoidRootPart”)
local clicks = player.leaderstats:WaitForChild(“Strenght”)
local function ToolName()
local fire1 = char:FindFirstChild("Fire1")
local fire2 = char:FindFirstChild("Fire2")
if fire1 then
part = fire1.Part:Clone()
elseif fire2 then
part = fire2.Part:Clone()
else
return
end
part.Parent = workspace.Stuff
part.Anchored = true
part.CanCollide = false
part.Transparency = 0.5
att = part:WaitForChild("Attachment")
partEmmit = att:WaitForChild("ParticleEmitter")
end
ToolName()
if not part or not att then
warn("No valid part or attachment found.")
return
end
local function emitterAmount()
local emitAmount
local fire1 = char:FindFirstChild("Fire1")
local fire2 = char:FindFirstChild("Fire2")
if fire1 and clicks.Value <= 50 then
emitAmount = math.floor(clicks.Value / 2)
elseif fire1 and clicks.Value > 50 then
emitAmount = 25
elseif fire2 and clicks.Value <= 100 then
emitAmount = math.floor(clicks.Value / 4)
elseif fire2 and clicks.Value > 100 then
emitAmount = 25
else
emitAmount = 1
end
return math.max(emitAmount, 1)
end
local offset = hrp.CFrame.LookVector * 5
part.CFrame = hrp.CFrame + offset
local emitter = att:FindFirstChild("ParticleEmitter")
if emitter then
local amountToEmit = emitterAmount()
emitter:Emit(amountToEmit)
print(amountToEmit, "particles emitted!")
print("Clicks:", clicks.Value)
task.delay(0.5, function()
part:Destroy()
end)
else
warn("No ParticleEmitter found.")
end
OMG I FIGURED IT OUT. My attachment was moved. What i mean by that is the position of att wasnt the same as the part. I am sorry for taking your time, but i think that without you i wouldnt be able to do it.