OnTouched script not responding to any touches

I’m making a gun for a group, it’s almost done except for the bullet that if hit, a player has to fade away with neon and stuff.
The effects I made onTouched were perfect, but the onTouched event doesn’t work for some reason.
In my script that I put inside of the bullet is this:
repeat wait() until script.Parent.Name ~= “BulletChilds”`

local IsTouched = false

local Bullet = script.Parent

print(Bullet.Name)

Bullet.Touched:Connect(function(Obj)
	print("Touch")
	if ((IsTouched == false)) and (Obj.Parent:FindFirstChild("Humanoid")) then
		IsTouched = true
		if Obj.Parent:FindFirstChild("Nova Rifle") then
			if Obj.Parent["Nova Rifle"].Owner.Value == script.Parent.Owner.Value then
				IsTouched = false
				return
			end
		end
		script.Parent.Hit:Play()
		if Obj.Parent:FindFirstChild("ForceField") then
			Obj.Parent.ForceField:Destroy()
		end
		for i,v in pairs(Obj.Parent.Head:GetChildren()) do
			if v:IsA("BillboardGui") then
				v:Destroy()
			end
		end
		Obj.Parent.Shirt:Destroy()
		Obj.Parent.Pants:Destroy()
		local HRP = Obj.Parent.HumanoidRootPart
		HRP.Anchored = true
		Obj.Parent.Animate:Destroy()
		for i=1,75 do
			for _,CharacterObject in pairs(Obj.Parent:GetChildren()) do
				if CharacterObject:IsA("Part") or CharacterObject:IsA("MeshPart") then
					CharacterObject.Material = Enum.Material.Neon
					CharacterObject.Color = script.Parent.Color
					CharacterObject.Transparency = CharacterObject.Transparency + .025
				elseif CharacterObject:IsA("Accessory") then
					CharacterObject.Handle.Transparency = CharacterObject.Handle.Transparency + .025
					CharacterObject.Handle.Mesh.TextureId = "http://www.roblox.com/asset/?id=4895102398"
				end
			end 
			Obj.Parent.Head.face.Transparency = Obj.Parent.Head.face.Transparency + .025
			game:GetService("RunService").Stepped:Wait()
		end
		wait(2)
		if game.Players:FindFirstChild(Obj.Parent.Name) then
			game.Players:GetPlayerFromCharacter(Obj.Parent):LoadCharacter()
		else
			Obj.Parent:Destroy()
		end
		wait(.5)
		script.Parent:Destroy()
	end
end)

Most of the stuff in there isn’t relevant but I put it in there anyways.
Also, I instance.new() each bullet and the clone in this script with some other sound effects and values.

local CosmeticBullet = Instance.new("Part")

CosmeticBullet.Material = Enum.Material.Neon

CosmeticBullet.Color = Color3.fromRGB(0, 196, 255)

CosmeticBullet.CanCollide = false

CosmeticBullet.Anchored = true

CosmeticBullet.Size = Vector3.new(0.4, 0.4, 8)

CosmeticBullet.Name = "NovaRifle_Bullet"


for i,v in pairs(script.Parent.BulletChilds:GetChildren()) do

v:Clone().Parent = CosmeticBullet

end

And yes, the “CosmeticBullet” is parented later on in the script, each time I fire the gun it just prints the bullets name so the script is loaded

Does anyone know how I could fix this?

1 Like

Where is the code by which you clone and parent the script?

1 Like

It’s the lower one…

local CosmeticBullet = Instance.new("Part")

CosmeticBullet.Material = Enum.Material.Neon

CosmeticBullet.Color = Color3.fromRGB(0, 196, 255)

CosmeticBullet.CanCollide = false

CosmeticBullet.Anchored = true

CosmeticBullet.Size = Vector3.new(0.4, 0.4, 8)

CosmeticBullet.Name = "NovaRifle_Bullet"


for i,v in pairs(script.Parent.BulletChilds:GetChildren()) do

v:Clone().Parent = CosmeticBullet

end

Try parenting the script(s) after you’ve parented the bullet to workspace.

Also, add a small wait to the start of the Touched script.

I feel like the problem here is that you’re destroying the script too quickly. Maybe try deleting it later?

1 Like

If You use script to move your parts. Try to used BodyVelocity instead of script

Well, I did not put effort in reading your script here, but f your bullet is moving on the firing of the gun, I guess the problem is the bullet is too quick for the onTouched event to run. If you’re making guns, RayCasting is always the preferred and the best idea.