Roblox randomly giving me an error

Alright so i got a script in serverscriptservice:

local ReplicatedStorage = game:GetService('ReplicatedStorage')
local remoteEvent = ReplicatedStorage:WaitForChild('ShotEvent')


local damage_amount = 10


remoteEvent.OnServerEvent:Connect(function(player, gunPos, gunOr, mosPos)



	local bullet = Instance.new('Part')
	
	

	bullet.Name = 'Bullet'

	bullet.Parent = game.Workspace

	bullet.Shape = Enum.PartType.Cylinder

	bullet.Size = Vector3.new(0.25, 0.25, 0.25)

	bullet.BrickColor = BrickColor.new('White')



	local speed = 250

	bullet.CFrame = CFrame.new(gunPos, mosPos)

	bullet.Velocity = bullet.CFrame.lookVector * speed



	bullet.Touched:Connect(function(otherPart)

		local humanoid = otherPart.Parent:FindFirstChild('Humanoid')

		if humanoid and humanoid.Parent.Name ~= player.Name then

			if humanoid.Health > 0 and humanoid.Health - damage_amount <= 0 then
				end

			end

			humanoid:TakeDamage(damage_amount)

		bullet:Destroy()
	end)
end)

and it worked before but now i get this

ServerScriptService.BulletCreate:47: attempt to index nil with ‘TakeDamage’

1 Like

the humanoid:TakeDamage() should be under if humanoid

1 Like