Need Help Fixing Glitch With FPS Pistol

So I was working on an fps system, and when the humanoid is supposed to take “25” damage when they get shot, the hit function gets fired multiple times so the humanoid ends up getting one shot, is there any way I could fix this?

local fireEvent = game.ReplicatedStorage.FireEvent
local FastCast = require(game.ReplicatedStorage.FastCastRedux)

local bulletsFolder = workspace:FindFirstChild("BulletFolder") or Instance.new("Folder", workspace)
bulletsFolder.Name = "BulletFolder"

local bulletTemplate = game.ReplicatedStorage.Bullet:Clone()

--FastCast.VisualizeCasts = true

local caster = FastCast.new()

local castParams = RaycastParams.new()
castParams.FilterType = Enum.RaycastFilterType.Blacklist
castParams.IgnoreWater = true

local castBehavior = FastCast.newBehavior()
castBehavior.RaycastParams = castParams
castBehavior.Acceleration = Vector3.new(0, -workspace.Gravity, 0)
castBehavior.AutoIgnoreContainer = false
castBehavior.CosmeticBulletContainer = bulletsFolder
castBehavior.CosmeticBulletTemplate = bulletTemplate

local function TagHumanoid(humanoid, player)
	local Creator_Tag = Instance.new("ObjectValue")
	Creator_Tag.Name = "creator"
	Creator_Tag.Value = player
	game:GetService("Debris"):AddItem(Creator_Tag, 2)
	Creator_Tag.Parent = humanoid
end

local function UntagHumanoid(humanoid)
	for i, v in pairs(humanoid:GetChildren()) do
		if v:IsA("ObjectValue") and v.Name == "creator" then
			v:Destroy()
		end
	end
end

local function onLengthChanged(cast, lastPoint, direction, length, velocity, bullet)
	if bullet then 
		local bulletLength = bullet.Size.Z/2
		local offset = CFrame.new(0, 0, -(length - bulletLength))
		bullet.CFrame = CFrame.lookAt(lastPoint, lastPoint + direction):ToWorldSpace(offset)
	end
end



local function fire(player, mousePosition, shotpart)
	castParams.FilterDescendantsInstances = {player, bulletsFolder}
	print(mousePosition, shotpart)
	local firePoint = shotpart
	local origin = firePoint
	local direction = (mousePosition - origin).Unit
	
	caster:Fire(origin, direction, 1500, castBehavior)
	
	local function onRayHit(cast, result, velocity, bullet)
		local hit = result.Instance

		local character = hit:FindFirstAncestorWhichIsA("Model")
		if character and character:FindFirstChild("Humanoid") then
			UntagHumanoid(hit.Parent)
			TagHumanoid(hit.Parent.Humanoid, player)
			character.Humanoid:TakeDamage(25)
			print("hit")
			ow = ow + 1
			elseif hit and hit.Parent:IsA("Accessory") and then
	hit.Parent.Parent.Humanoid:TakeDamage(25)
	UntagHumanoid(hit.Parent)
			TagHumanoid(hit.Parent.Parent.Humanoid, hit)
		end

		game:GetService("Debris"):AddItem(bullet, 0.1)
	end
	caster.RayHit:Connect(onRayHit)
end

fireEvent.OnServerEvent:Connect(fire)


caster.LengthChanged:Connect(onLengthChanged)

Any help would be appreciated thanks!

I would disconnect RayHit:Connect() after a hit regardless of if a humanoid is found because the ray may have hit a wall

I don’t know how FastCast works, but you should probably disable the ray or also disconnect the function after N seconds because right now, it looks like each time you shoot, it makes a bullet path that will deal damage to anyone that walks through, even 10 seconds after the bullet was shot

i did got that problem when scripting a gun hit with the FastCast Module normally whats happening is a bug when u hit something it will take 25 dmg but u hit it again it will take 25 + 25 hit then hit again 25 + 25 + 25 etc… its a very weird glitch i fixed it by not using ray hit for dmg i just made my own raycast and then for the ray hit i used it just to destroy the bullet