Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make my fireball script not damage the player who casts it?

I have a local script and a script and a remote event for the fireball, I have no problems except I have no clue at all to make it so that the caster of the fireball doesn't get damaged by the fireball.

Script in ServerScriptService:

game:GetService("ReplicatedStorage").RemoteEvent.OnServerEvent:Connect(function(plr)
	
	local fireball = game:GetService("Lighting").FireBending.Fire1
	local char = plr.Character
	 
	local fire = fireball:Clone()
	fire.Parent = workspace
	fire.CFrame = char.Humanoid.Torso.CFrame * CFrame.new(0,0,-10)
	 
	local bodyv = Instance.new("BodyVelocity")
	bodyv.MaxForce = Vector3.new(1e8,1e8,1e8)
	bodyv.Velocity = char.Humanoid.Torso.CFrame.lookVector * 150
    bodyv.Parent = fire
	 
	local fireanim1 = char.Humanoid:LoadAnimation(script.FireAnim1)
	local fireanim2 = char.Humanoid:LoadAnimation(script.FireAnim2)
	local fireanim3 = char.Humanoid:LoadAnimation(script.FireAnim3)
	local choose = math.random(1,3)
	if choose == 1 then
	    fireanim1:Play()
	elseif choose == 2 then
     	fireanim2:Play()
	elseif choose == 3 then
	    fireanim3:Play()
	end
	 
	wait(2)
		fire:Destroy()
end)

And the LocalScript in the player's backpack:

local UserInputService = game:GetService("UserInputService")
local plr = game:GetService("Players").LocalPlayer
local mouse = plr:GetMouse()
local char = plr.Character or plr.CharacterAdded:wait()
local fireball = game:GetService("Lighting"):WaitForChild("FireBending").Fire1
local canattack = true
local checkdeath = true
	 
UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	if input.KeyCode == Enum.KeyCode.Z and canattack == true and not gameProcessedEvent then
		game:GetService("ReplicatedStorage").RemoteEvent:FireServer()
		canattack = false
		wait(3)
		canattack = true
	end
end)

3 comments

0

Spawn the fireball a little farther away from player?

1

So basically, just check if the parent name of the hit is not the player's name.

2

when spawning the fireball, add a stringvalue under the fireball that lists the player who cast it as its value, the damage script should then check that the person it touched doesn't have a name matching the tag

1 answer

✓ Accepted answer

You can use :IsDescendantOf() to check if a part is a descendant of another. We can have the fireball check if the part it hits is not a descendant of the character who created the fireball, and if so, damage them.

fire.Touched:Connect(function(Hit)
	if hit.Parent:FindFirstChild("Humanoid") then --check if the hit part is part of a player or NPC
		if not Hit:IsDescendantOf(character) then --checks if the hit part is NOT a descendant of the character
			--Code here
		end
	end
end)

3 comments

0

I think you mean ":IsAncestorOf()".

0

An ancester is like a parent of a parent, a descendant is like a child of a child, we check if the hit is a child or child of child of the character model.

0

Oh yeah, I forgot. Sorry about that.

This discussion is preserved as it was. New answers, comments, and votes are closed.