You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I’m trying to make a magic game when the player says fire it will active the particles inside the candle model -
What is the issue? Include screenshots / videos if possible!
Everything is working correctly it’s even printing but it’s jus not enabling the particles -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local FireSpellEvent = ReplicatedStorage:WaitForChild("LightCandleEvent") -- RemoteEvent for spell handling
FireSpellEvent.OnServerEvent:Connect(function(player, candle, action)
-- Check if the player has unlocked magic
if not player:GetAttribute("CanUseMagic") then
print(player.Name .. " does not have magic unlocked.")
return
end
-- Check if the player has enough mana
local currentMana = player:GetAttribute("Mana")
local spellCost = 5
if currentMana < spellCost then
print(player.Name .. " does not have enough mana to cast this spell.")
return
end
-- Validate the candle and locate the Hitbox
if candle and candle:IsDescendantOf(workspace) then
local hitbox = candle:FindFirstChild("Hitbox")
if not hitbox then
print("No Hitbox found for candle:", candle.Name)
return
end
-- Locate the Wick inside the Hitbox
local wick = hitbox:FindFirstChild("Wick")
if not wick then
print("No Wick found inside Hitbox for candle:", candle.Name)
return
end
-- Find all ParticleEmitters in the Wick
local particleEmitters = {}
for _, descendant in ipairs(wick:GetDescendants()) do
if descendant:IsA("ParticleEmitter") then
table.insert(particleEmitters, descendant)
end
end
-- Check if any ParticleEmitters exist
if #particleEmitters == 0 then
print("No ParticleEmitters found in Wick for candle:", candle.Name)
return
end
-- Handle the "fire" or "off" action
if action == "fire" then
-- Deduct mana and enable all ParticleEmitters
player:SetAttribute("Mana", math.clamp(currentMana - spellCost, 0, math.huge))
for _, emitter in ipairs(particleEmitters) do
emitter.Enabled = true -- Enable the particle emitters
print("Enabled ParticleEmitter for:", candle.Name)
end
print(player.Name .. " lit the candle:", candle.Name)
elseif action == "off" then
-- Disable all ParticleEmitters
for _, emitter in ipairs(particleEmitters) do
emitter.Enabled = false -- Disable the particle emitters
print("Disabled ParticleEmitter for:", candle.Name)
end
print(player.Name .. " extinguished the candle:", candle.Name)
end
-- Update the player's GUI
ReplicatedStorage:WaitForChild("UpdateManaGUI"):FireClient(player, player:GetAttribute("Mana"), player:GetAttribute("MaxMana"), true)
else
print("Invalid candle or candle not found in Workspace:", candle and candle.Name or "nil")
end
end)
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.