Script is not working and wont give me any hint to why

I have absolutely no hint on why this script will not work. it was working perfectly fine, but now it just wont respond to me. it wont damage players, or emit particles. and it goes through the entire script without doing anything. i had it print the part it hit with a raycast, and the position it hit, and when the script was done, i had it print “end of script.”


this is all it gives me, it prints what i told it to print without errors.

this is the script.

shootanim.AnimationId = "rbxassetid://15144487373"
local tool = script.Parent
local Fired = script.Parent.BR15Fire
local players = game:GetService("Players")
if script.Parent.Parent.ClassName ~= "Model" then
	repeat
		wait()
	until script.Parent.Parent.ClassName == "Model"
end
local animator = script.Parent.Parent.Humanoid.Animator
local shootanimtrack = animator:LoadAnimation(shootanim)

local barrel = tool.particles

local range = 800
Fired.OnServerEvent:Connect(function(player, mouseHit)
	shootanimtrack:Play(0, 0.1)
		tool.particles.flash1:Emit(10)
		tool.particles.flash2:Emit(10)
		tool.particles.smoke:Emit(100)
		tool.particles.fire:Play()
		tool.particles.firedistant:Play()
	local headDamage = math.random(35, 60)
	local bodyDamage = math.random(15, 20)
	local limbDamage = math.random(7.5, 10)
	local helmDamage = math.random(10, 15)
	local vestDamage = math.random(10, 15)
	if player.Name == tool.Parent.Name then
		local raycast = workspace:Raycast(barrel.Position, (mouseHit - barrel.Position).Unit * range)
		local hitpart = raycast.Instance
		local resultingpos = raycast.Position
		if hitpart then
			print(hitpart.Name)
			print(raycast.Position)
		if hitpart.ClassName == "Part" and not hitpart.Parent:FindFirstChildWhichIsA("Humanoid") then
			tool.impactparticles.Position = raycast.Position
			tool.impactparticles.Orientation = barrel.Orientation
			tool.impactparticles.smoke:Emit(20)
			tool.impactparticles.sparks:Emit(25)
			return
		elseif  hitpart.Parent == player.Character then
			return
		else	if hitpart.Parent:FindFirstChildWhichIsA("Humanoid") then 
				tool.impactparticles.Position = raycast.Position
					tool.impactparticles.Rotation = barrel.Rotation
				end
				local h = hitpart.Parent:FindFirstChildWhichIsA("Humanoid")
			if hitpart.Name == "Head" and hitpart.Parent.Head.Helmeted.Value == false then
					h:TakeDamage(headDamage)
						hitpart.Parent.Torso.miscpart.Attachment0.Orientation = barrel.Orientation
						tool.impactparticles.blood:Emit(165)
						tool.impactparticles.bloodmist:Emit(20)
						tool.impactparticles.impactbody:Play()
					tool.impactparticles.headshot:Emit(85)
					tool.impactparticles.headshotbone:Emit(100)
					tool.impactparticles.headshot1:Play()
						if h.Health <= 0 and not h.Dead then
							player.Money.Value += 15
							local dead = Instance.new("BoolValue")
							dead.Parent = h
						dead.Name = "Dead"
						if hitpart.Name == "Head" and hitpart.Parent.Head.Helmeted.Value == false then
							h:TakeDamage(helmDamage)
							hitpart.Parent.Torso.miscpart.Attachment0.Orientation = barrel.Orientation
							tool.impactparticles.sparkshelmet:Emit(400)
							hitpart.Helmet.Helmetbroke.Enabled = true
							if h.Health <= 0 and not h.Dead then
								player.Money.Value += 15
								local dead = Instance.new("BoolValue")
								dead.Parent = h
								dead.Name = "Dead"
				elseif hitpart.Name == "Torso" or hitpart.Name == "HumanoidRootPart" and not hitpart.Parent.Torso.Lightvest then
						h:TakeDamage(bodyDamage)
						tool.impactparticles.blood:Emit(165)
						tool.impactparticles.bloodmist:Emit(20)
						tool.impactparticles.impactbody:Play()
					hitpart.Parent.Torso.miscpart.Attachment0.Orientation = barrel.Orientation
							if h.Health <= 0 and not h.Dead then
								player.Money.Value += 15
								local dead = Instance.new("BoolValue")
								dead.Parent = h
								dead.Name = "Dead"
							elseif hitpart.Name == "Torso" or hitpart.Name == "HumanoidRootPart" and hitpart.Parent.Torso.LightVest then
								h:TakeDamage(vestDamage)
								tool.impactparticles.vestsmoke:Emit(25)
								tool.impactparticles.hitvest:Play()
								hitpart.Parent.Torso.miscpart.Attachment0.Orientation = barrel.Orientation
								if h.Health <= 0 and not h.Dead then
									player.Money.Value += 25
									local dead = Instance.new("BoolValue")
									dead.Parent = h
									dead.Name = "Dead"
				elseif hitpart.Name == "Right Arm" or hitpart.Name == "Right Leg" or hitpart.Name == "Left Arm" or hitpart.Name == "Left Leg" then
						h:TakeDamage(limbDamage)
						tool.impactparticles.blood:Emit(165)
						tool.impactparticles.bloodmist:Emit(20)
						tool.impactparticles.impactbody:Play()
					hitpart.Parent.Torso.miscpart.Attachment0.Orientation = barrel.Orientation
								if h.Health <= 0 and not h.Dead then
									player.Money.Value += 15
									local dead = Instance.new("BoolValue")
									dead.Parent = h
											dead.Name = "Dead"
										end
									end
								end
							end
						end
					end
				end					
			end
		end
	end
	print("end of script")
end)

Please help!

3 Likes

I added a bunch of print/warn commands after every IF in the script.

See if any of them print.

shootanim.AnimationId = "rbxassetid://15144487373"
local tool = script.Parent
local Fired = script.Parent.BR15Fire
local players = game:GetService("Players")
if script.Parent.Parent.ClassName ~= "Model" then
	repeat
		wait()
		print("Waiting")
	until script.Parent.Parent.ClassName == "Model"
end
local animator = script.Parent.Parent.Humanoid.Animator
local shootanimtrack = animator:LoadAnimation(shootanim)

local barrel = tool.particles

local range = 800
Fired.OnServerEvent:Connect(function(player, mouseHit)
	shootanimtrack:Play(0, 0.1)
	tool.particles.flash1:Emit(10)
	tool.particles.flash2:Emit(10)
	tool.particles.smoke:Emit(100)
	tool.particles.fire:Play()
	tool.particles.firedistant:Play()
	local headDamage = math.random(35, 60)
	local bodyDamage = math.random(15, 20)
	local limbDamage = math.random(7.5, 10)
	local helmDamage = math.random(10, 15)
	local vestDamage = math.random(10, 15)
	if player.Name == tool.Parent.Name then
		local raycast = workspace:Raycast(barrel.Position, (mouseHit - barrel.Position).Unit * range)
		local hitpart = raycast.Instance
		local resultingpos = raycast.Position
		if hitpart then
			print(hitpart.Name)
			print(raycast.Position)
			if hitpart.ClassName == "Part" and not hitpart.Parent:FindFirstChildWhichIsA("Humanoid") then
				print("YES: hitpart.ClassName == Part")
				tool.impactparticles.Position = raycast.Position
				tool.impactparticles.Orientation = barrel.Orientation
				tool.impactparticles.smoke:Emit(20)
				tool.impactparticles.sparks:Emit(25)
				return
			elseif  hitpart.Parent == player.Character then
				print("YES: hitpart.Parent == player.Character")
				return
			else
				if hitpart.Parent:FindFirstChildWhichIsA("Humanoid") then
					print("YES: hitpart.Parent:FindFirstChildWhichIsA(Humanoid)")
					tool.impactparticles.Position = raycast.Position
					tool.impactparticles.Rotation = barrel.Rotation
				end
				local h = hitpart.Parent:FindFirstChildWhichIsA("Humanoid")
				if hitpart.Name == "Head" and hitpart.Parent.Head.Helmeted.Value == false then
					print("YES: hitpart.Name == Head and hitpart.Parent.Head.Helmeted.Value == false")
					h:TakeDamage(headDamage)
					hitpart.Parent.Torso.miscpart.Attachment0.Orientation = barrel.Orientation
					tool.impactparticles.blood:Emit(165)
					tool.impactparticles.bloodmist:Emit(20)
					tool.impactparticles.impactbody:Play()
					tool.impactparticles.headshot:Emit(85)
					tool.impactparticles.headshotbone:Emit(100)
					tool.impactparticles.headshot1:Play()
					if h.Health <= 0 and not h.Dead then
						print("YES: h.Health <= 0 and not h.Dead")
						player.Money.Value += 15
						local dead = Instance.new("BoolValue")
						dead.Parent = h
						dead.Name = "Dead"
						if hitpart.Name == "Head" and hitpart.Parent.Head.Helmeted.Value == false then
							print("YES: hitpart.Name == Head and hitpart.Parent.Head.Helmeted.Value == false")
							h:TakeDamage(helmDamage)
							hitpart.Parent.Torso.miscpart.Attachment0.Orientation = barrel.Orientation
							tool.impactparticles.sparkshelmet:Emit(400)
							hitpart.Helmet.Helmetbroke.Enabled = true
							if h.Health <= 0 and not h.Dead then
								print("YES: h.Health <= 0 and not h.Dead")
								player.Money.Value += 15
								local dead = Instance.new("BoolValue")
								dead.Parent = h
								dead.Name = "Dead"
							elseif hitpart.Name == "Torso" or hitpart.Name == "HumanoidRootPart" and not hitpart.Parent.Torso.Lightvest then
								print("YES: hitpart.Name == Torso or hitpart.Name == HumanoidRootPart and not hitpart.Parent.Torso.Lightvest")
								h:TakeDamage(bodyDamage)
								tool.impactparticles.blood:Emit(165)
								tool.impactparticles.bloodmist:Emit(20)
								tool.impactparticles.impactbody:Play()
								hitpart.Parent.Torso.miscpart.Attachment0.Orientation = barrel.Orientation
								if h.Health <= 0 and not h.Dead then
									print("YES: h.Health <= 0 and not h.Dead")
									player.Money.Value += 15
									local dead = Instance.new("BoolValue")
									dead.Parent = h
									dead.Name = "Dead"
								elseif hitpart.Name == "Torso" or hitpart.Name == "HumanoidRootPart" and hitpart.Parent.Torso.LightVest then
									print("YES: hitpart.Name == Torso or hitpart.Name == HumanoidRootPart and hitpart.Parent.Torso.LightVest")
									h:TakeDamage(vestDamage)
									tool.impactparticles.vestsmoke:Emit(25)
									tool.impactparticles.hitvest:Play()
									hitpart.Parent.Torso.miscpart.Attachment0.Orientation = barrel.Orientation
									if h.Health <= 0 and not h.Dead then
										print("YES: h.Health <= 0 and not h.Dead")
										player.Money.Value += 25
										local dead = Instance.new("BoolValue")
										dead.Parent = h
										dead.Name = "Dead"
									elseif hitpart.Name == "Right Arm" or hitpart.Name == "Right Leg" or hitpart.Name == "Left Arm" or hitpart.Name == "Left Leg" then
										print("YES: hitpart.Name == Right Arm or hitpart.Name == Right Leg or hitpart.Name == Left Arm or hitpart.Name == Left Leg")
										h:TakeDamage(limbDamage)
										tool.impactparticles.blood:Emit(165)
										tool.impactparticles.bloodmist:Emit(20)
										tool.impactparticles.impactbody:Play()
										hitpart.Parent.Torso.miscpart.Attachment0.Orientation = barrel.Orientation
										if h.Health <= 0 and not h.Dead then
											print("YES: h.Health <= 0 and not h.Dead")
											player.Money.Value += 15
											local dead = Instance.new("BoolValue")
											dead.Parent = h
											dead.Name = "Dead"
										end
									end
								end
							end
						end
					end
				end					
			end
		else
			warn("FALSE: hitpart")
		end
	else
		warn("FALSE: player.Name == tool.Parent.Name")
	end
	print("end of script")
end)
1 Like

Code enclosed in double quotes indicates that it is a string. In a string, the content is treated as plain text and is not evaluated or executed as code. Meaning, your script will just print YES: hitpart.Name == Head and hitpart.Parent.Head.Helmeted.Value == false

For it to work as intended, you will need to use the .. operator which is used for concatenating strings together

print("YES: " .. hitpart.Name == Head and hitpart.Parent.Head.Helmeted.Value == false)

Alternatively, you can use string.format.

print(string.format("YES: %s and %s == %s", tostring(hitpart.Name == Head), "hitpart.Parent.Head.Helmeted.Value", tostring(hitpart.Parent.Head.Helmeted.Value == false)))

1 Like

Don’t see an obvious logic errors … as long as everything it’s calling is there, it should work.
Re-wrote it a bit, changes to simplify and optimize.

local tool = script.Parent
local Fired = tool.BR15Fire
local range = 800

Fired.OnServerEvent:Connect(function(player, mouseHit)
    local hitPart, hitPosition = workspace:FindPartOnRay(Ray.new(tool.particles.Position, (mouseHit - tool.particles.Position).Unit * range))

    if not hitPart then
        return
    end

    if hitPart.Parent == player.Character then
        return
    end

    local h = hitPart.Parent:FindFirstChildWhichIsA("Humanoid")
    if not h then
        tool.impactparticles.Position = hitPosition
        tool.impactparticles.Orientation = tool.particles.Orientation
        tool.impactparticles.smoke:Emit(20)
        tool.impactparticles.sparks:Emit(25)
        return
    end

    local headDamage = math.random(35, 60)
    local bodyDamage = math.random(15, 20)
    local limbDamage = math.random(7.5, 10)
    local helmDamage = math.random(10, 15)
    local vestDamage = math.random(10, 15)

    tool.impactparticles.Position = hitPosition
    tool.impactparticles.Rotation = tool.particles.Rotation
    tool.impactparticles.blood:Emit(165)
    tool.impactparticles.bloodmist:Emit(20)
    tool.impactparticles.impactbody:Play()

    if hitPart.Name == "Head" and not hitPart.Parent.Head.Helmeted.Value then
        h:TakeDamage(headDamage)
        tool.impactparticles.headshot:Emit(85)
        tool.impactparticles.headshotbone:Emit(100)
        tool.impactparticles.headshot1:Play()
    elseif hitPart.Name == "Torso" or hitPart.Name == "HumanoidRootPart" then
        if not hitPart.Parent.Torso.Lightvest then
            h:TakeDamage(bodyDamage)
        else
            h:TakeDamage(vestDamage)
            tool.impactparticles.vestsmoke:Emit(25)
            tool.impactparticles.hitvest:Play()
        end
    else
        h:TakeDamage(limbDamage)
    end

    if h.Health <= 0 and not h.Dead then
        player.Money.Value += 15
        local dead = Instance.new("BoolValue", h)
        dead.Name = "Dead"
    end

    if hitPart.Name == "Head" and hitPart.Parent.Head.Helmeted.Value == false then
        h:TakeDamage(helmDamage)
        tool.impactparticles.sparkshelmet:Emit(400)
        hitPart.Helmet.Helmetbroke.Enabled = true
        if h.Health <= 0 and not h.Dead then
            player.Money.Value += 15
            local dead = Instance.new("BoolValue", h)
            dead.Name = "Dead"
        end
    end
end)
1 Like

i have had a issue similar to this before. Try using Runservice:Wait() before emitting the particles that hsould fix it.

1 Like

This makes the gun do unarmored damage on any armored parts, and only checks if there is a LightVest, not if there isnt one.

1 Like

Ya, it’s just a guess without anything to work with.

1 Like

i figured the issue out, the RemoteEvent just will not fire “OnServerEvent.” no matter what i do, it wont fire. i checked the variable’s spacing and thats all perfectly fine, there’s no errors, i guess this is just an engine bug

1 Like

Pull away from the main program, create a scratch program just to do, and work with that until you get it perfected. Then come back and incorporate it into the main program. Flipitagainpls makes a good point … Stepped:Wait() is more than powerful as it is also synced to the FPS update. When things that seem they should work but are not, always seem to come down to a missed synced wait. Have to watch what you name things also. Unique names are key. Sometimes you think you are calling something when in fact you are calling something already defined … then things are hard to debug.

1 Like