Launching Projectile Hits Caster

I’ve been working on a spell casting system using keydown which works well enough. I have the intention to make the spell hit a player and/or npc and apply damage to them however I’ve currently hit a wall and can’t work out how to fix it.

The spell uses the Touched function, so that when the ball hits the player/npc it’ll make the hit part transparent (For testing purposes). The only issue is that it also registers the caster as hit and makes their left arm (Where the ball originates from) transparent. How can I stop this from happening?

This is the code so far in a server script.

local remote = game.ReplicatedStorage["Force Powers"].Push.Push



remote.OnServerEvent:Connect(function(plr,mouse)
	local p = plr
	local LArm = p.Character:FindFirstChild("Left Arm")
	
	local PushMod = game.ServerStorage.ForcePush
	local PushModClone = PushMod:Clone()
	
	
	wait(.5)
	
	PushModClone.Parent = workspace["Force Effects"]
	PushModClone.Position = LArm.Position + Vector3.new(-1, 0, 0)
	
	print(mouse)
	
	local BV = Instance.new("BodyVelocity")
	BV.Parent = PushModClone
	BV.P = 100000000
	BV.MaxForce = Vector3.new(1,1,1) * 10000000
	BV.Velocity = (mouse - LArm.Position) * 50
	
	
	PushModClone.Touched:Connect(function(hit)
		local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
		if player then
			print(hit.Name)
			hit.Transparency = 1
		end
	end)
	
	wait(5)
	PushModClone:Destroy()
	

	print("Server fired event")
		
end)
2 Likes

When the RemoteEvent was fired, plr got passed through as a parameter. Now you just need to compare the player that was hit with plr that fired the Event.

PushModClone.Touched:Connect(function(hit)
	local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	if player and player ~= plr then --If player exists and player is not equal to plr that fired event
		print(hit.Name)
		hit.Transparency = 1
	end
end)
2 Likes

I can’t believe it was one line of code that needed to be added haha. You’re a live saver, thank you so much!

2 Likes