I’m making a flamethrower and am very confused; I’m 100% sure that these are the lines of code that’s making it not work correctly. My flamethrower only lights a single person until you start firing again. The line of code that isn’t working:
while firing do
local ray = Ray.new(ft.FlamePart.Position, -25*ft.FlamePart.CFrame.upVector)
local hitPart = workspace:FindPartOnRayWithIgnoreList(ray, player.Character:GetChildren())
if hitPart then
print(hitPart.Name)
if hitPart.Parent:FindFirstChild("Humanoid") then
ignite(hitPart.Parent)
end
end
wait()
end
end
I’m not sure why it isn’t working properly, so help would be appreciated!
Could you show the ignite function? If it has any kind of waiting that isn’t done in a different coroutine, it prevents the loop you posted from continuing until all the waits in it are done.
function ignite(character)
if not taggedTargets:Find(character) then
table.insert(taggedTargets, 1, character)
character.Humanoid.WalkSpeed = 0
for _, child in pairs(character:GetChildren()) do
if child:IsA("Part") then
local flame = ft.FlamePart.Flame:Clone()
flame.Size = NumberSequence.new({NumberSequenceKeypoint.new(0.0, 2), NumberSequenceKeypoint.new(0.2, 1.5), NumberSequenceKeypoint.new(0.4, 1), NumberSequenceKeypoint.new(0.6, 0.5), NumberSequenceKeypoint.new(0.8, 0.25), NumberSequenceKeypoint.new(1.0, 0.2)})
flame.Lifetime = NumberRange.new(0.25, 1.5)
flame.EmissionDirection = Enum.NormalId.Top
flame.Acceleration = Vector3.new(0, 5, 0)
flame.Parent = child
end
end
Keep a reference of the parts that have already been hit (append to table). This table is your ignore list, use it as the second argument of the Raycast.
workspace:FindPartOnRayWithIgnoreList is deprecated. Preferably use workspace:Raycast().
In addition to the script, I have a client script which handles some functions for the client. Whenever it fires the :Fire function, it gives me the error “Unable to cast Array to Vector3”
local ray = RaycastParams.new()
ray.FilterType = Enum.RaycastFilterType.Whitelist
ray.FilterDescendantsInstances = {ray, player.Character:GetChildren()}
ray.IgnoreWater = true
local hitPart = workspace:Raycast(ft.FlamePart.Position, -25, ft.FlamePart.CFrame.upVector)
if hitPart then
print(hitPart.Name)
if hitPart.Parent:FindFirstChild("Humanoid") then
ignite(hitPart.Parent)
end
end
wait()
end
end
Please read this page: Raycasting | Roblox Creator Documentation.
The function workspace:RayCast() returns a RaycastResult object, not the part that was hit. The (possible) hit can be retrieved by calling .Instance on the returned RaycastResult.
Keep a reference table:partsHit = {}
Everytime a part is lit on fire, append it to that table: table.insert(partsHit, partThatWasHit).
Additionally, you can insert the player’s character parts to that table.
Set this table as the FilterDescendantInstances of your RaycastParams, and make sure to use a blacklist to exclude the parts in the table.