So basically i want to make a spell casting system, but how would I go about making things like AOE spells NOT effect the spell caster? I've thought and researched but couldn't come up with anything, sorry that I can't provide any code...
✓ ANSWER ACCEPTED
Line of code that would make an action ignore the player who starts it?
1 answer
✓ Accepted answer
Not sure how to phrase this answer but when you're creating the AOE attack pass it the name of the player who cast the spell as an argument and then don't apply the spell to them, for example:
local player = game:GetService("Players").LocalPlayer
local function castAreaSpell(caster)
-- create a part to act as the Area Of Effect (AOE)
local area = Instance.new("Part")
area.Size = Vector3.new(20, 20, 20)
area.Anchored = true
area.Position = player.Character.HumanoidRootPart.Position
area.Parent = game.Workspace
-- get all parts within the AOE,
-- if the part is the child of a player character,
-- add it to table touchingChars
local touchingParts, touchingChars = area:GetTouchingParts(), {}
for _, part in pairs(touchingParts) do
if game:GetService("Players"):GetPlayerFromCharacter(part.Parent) and not touchingChars[part.Parent] then
touchingChars[part.Parent] = true
end
end
-- loop through all the chars in touchingChars
-- and apply effect of spell as long as the char is not the spell caster
for _, char in pairs(touchingChars) do
if not char.Name == caster.Name then
-- apply effect of spell
end
end
-- clean up the mess
area:Destroy()
end
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
thank :))