Why doesn't this part of the script only fire when the part touches a player's character?

  1. What do you want to achieve? a script that shoots a fireball and does damage when it hits a player

  2. What is the issue? the damaging part of the script fires whenever, not when it touches a player

  3. What solutions have you tried so far? none since I don’t understand

here’s the script

local replicatedStorage = game:GetService("ReplicatedStorage")

replicatedStorage.WandaRemotes.WandaBlast.OnServerEvent:Connect(function(player, position)
	local character = player.Character
	
	local blast = replicatedStorage.WandaPowers.WandaBlast:Clone()
	blast.Parent = workspace
	blast.Position = character.HumanoidRootPart.Position + Vector3.new(0,0,-1)
	
	local explosion = replicatedStorage.WandaPowers.WandaHit:Clone()
	
	local bv = Instance.new("BodyVelocity")
	bv.Velocity = CFrame.new(blast.Position, position).LookVector * 75
	bv.Parent = blast
	
	blast.Touched:Connect(function(hit)
		if hit.Parent.Name == player.Name then return end
		
		if hit.Parent.Humanoid then
			hit.Parent.Humanoid:TakeDamage(10)
		end
		
		blast:Destroy()
		explosion.Position = blast.Position
		explosion.Parent = workspace
		wait(0.1)
		for i = 1, 10 do
			wait(0.1)
			explosion.Attachment.b.Rate -= 3
			explosion.Attachment.c.Rate -= 3
		end
		wait(1)
		explosion:Destroy()
		
	end)
end)

please note that players have custom 3d clothing on them that are placed inside of accessories (pretty much meshes that stick onto the player with WeldConstraints and they’re non-collidable with canTouch set to false) here’s what it looks like:

1 Like
--inside .Touched event
local hum = hit.Parent.Humanoid
--if the part isn't a humanoid BodyPart, do not run the rest of the script(the explosion)
if not hum then return end
hum:TakeDamage(10)
--rest of the code

In other words, you forgot to use return in order to stop the rest of the script from running, if the part isn’t a child of a character.

2 Likes

I think this part of the script should look more like this, Because you’re deleting the part you’re getting the position from

explosion.Position = blast.Position
blast:Destroy()
explosion.Parent = workspace
1 Like

haven’t thought of that, thank you!

1 Like

worked flawlessly, thank you so much

2 Likes