Hello! I’m currently working on a magic game, and my problem is that my projectile is also damaging the caster.
How do I do this?
Hello! I’m currently working on a magic game, and my problem is that my projectile is also damaging the caster.
How do I do this?
It’s a lot easier to help if you provide more information, especially the code you’re currently using that doesn’t quite do what you want.
You should use an ‘if-statement’ which checks of the projectile hit the caster or not. You can store the value of the caster locally or on server.
Assuming whatever magic you send out (probably a part with body movers or something), and do damage based on .Touched
this is super easy to fix.
A simple if statement
to check when the magic is touched if the part it touched is in the player’s character.
-- Here is a script example because I am bad at explaining things in words.
magic.Touched:Connect(function(hit) -- Hit is what touched the magic.
if not hit.Parent:IsDescendantOf(character) then -- Make sure it isn't in the character.
-- do magic stuff and damage here.
end
end)
This script assumes you have the caster’s character already defined and magic
is defined.
Now, touched events aren’t that reliable but it works if you just want a pretty simple system.
So I have a tool that will cast the projectile, and the projectile will be in the workspace and I have no idea how to define the caster’s character like that, how should I do that?
When you clone the projectile, add a “StringValue” into the cloned projectile and set the value to the player’s name.
Once a player is hit, check if the StringValue’s Value is equal to the Hit Character’s name.
There has to be some code that does damage if it is damaging the castor. You need to add a check to see if the hit item is the same as the player firing it. This will be somewhere in the tools server script. Just search for Touch. There is probably an if statement to check and see if the thing hit has a humanoid or not. You could just add to this statement like this:
if hit.Parent:FindFirstChild("Humanoid") ~= nil then
change to
if hit.Parent:FindFirstChild("Humanoid") ~= nil and hit.Parent.Name ~= player.Name then --or whatever player is defined as