Another script bugging me

Hi there once again i come for your magic help. does anybody actualy knows why this loops forever instead of just activating when you have the 2 weapons and deactivating when you got none of them 2 ?


local bagActive = false
local bagEntity = nil
local this = false
local weapon ={
"WEAPON_ASSAULTRIFLE",
"WEAPON_CARBINERIFLE", 
}




Citizen.CreateThread(function()
	while true do
		local playerPed = GetPlayerPed(-1)
		for i=1, #weapon, 1 do
    		local weaponHash = GetHashKey(weapon[i])
    		if HasPedGotWeapon(playerPed, weaponHash, false) 
                if  not this then
	      			EnableX()
                    drawNotification('~r~X enabled')	
                    this = true
		        end
      			elseif not HasPedGotWeapon(playerPed, weaponHash, false)
               if  this then
					DisableX()
                    drawNotification('~r~X disabled')
                   this = false
      			end
			end
  		end
		Wait(500)
	end
end)

Later edit … the break solved it only if it’s the first weapon from the list , if it’s not it just cycle and does the same check and continuously enables/disables X function … bump… help needed so if the player has any of the weapon from the list … X function stays active… doesn’t trigger continous enable/disable.

1 Like

Bump … anyone ?

This is from the native docs

Bool does not check if the weapon is current equipped, unfortunately.

Maybe try a different native. If you would like a reference that could help you go get whether a player has a model weapon take a look at my Taser Cartridge script.

I don’t want to know if the eapon is equiped. I only want to know if the user has any of the weapons in his inventory , while he has any big weapon …it will trigger X witch shows a bag. Basicaly every person with a big weapon will have a bag.

nevermind finally fixed it