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?