If statement doesn't run despite requirements being met

I have a module script and a local script

the local scripts detects whenever a child is added to the character, and does its thing
then, there’s an if statement that checks for the weapon type of the tool, for some reason this will not run when the requirements are met

yes, the tool has a StringValue with the weapon type in it


module script:

local info = {
	-- // GUNS
	-----------------------------------------------------
	-- // AUTOMATICS
	MP9S = {
		MAX_BULLETS = 30,
		WEAPON_TYPE = "GUN",
		GUN_TYPE = "AUTOMATIC",
		FIRERATE = 0.06
	},
	
	AK12 = {
		MAX_BULLETS = 95,
		WEAPON_TYPE = "GUN",
		GUN_TYPE = "AUTOMATIC",
		FIRERATE = 0.1,
	},
	-----------------------------------------------------
	-- // SEMIS
	Glock18 = {
		MAX_BULLETS = 18,
		WEAPON_TYPE = "GUN",
		GUN_TYPE = "SEMI",
		FIRERATE = 0.09
	},
	
	Fiveseven = {
		MAX_BULLETS = 15,
		WEAPON_TYPE = "GUN",
		GUN_TYPE = "SEMI"
	},
	
	RXK = {
		MAX_BULLETS = 6,
		WEAPON_TYPE = "GUN",
		GUN_TYPE = "SEMI"
	}
	-----------------------------------------------------
}

return info

local script

local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local animator = humanoid:FindFirstChildOfClass("Animator")

-- // SERVICES AND EVENTS
local RS = game:GetService("ReplicatedStorage")
local ShootEvent = RS:WaitForChild("GunEvents").ShootEvent
local DisableIsHoldingEvent = RS:WaitForChild("GunEvents").DisableIsHoldingEvent
local UpdateHitPosEvent = RS:WaitForChild("GunEvents").UpdateHitPosEvent

-- // MOUSE AND MODULE SCRIPT
local mouse = plr:GetMouse()
local gunStats = require(RS.ClientWeaponStats)

-- // MISC
local weapon = nil
local shooting = false

char.ChildAdded:Connect(function(child)
	if not child:IsA("Tool") then return end
	weapon = child
	if weapon.WeaponType == gunStats[weapon.Name]["WEAPON_TYPE"] then -- anything past this if statement does not run :(	
		print("bababababa")
		local Shooting = weapon:WaitForChild("Shooting")
		local Reloading = weapon:WaitForChild("Reloading")
		local Bullets = weapon:WaitForChild("Bullets")
		
		local Shoot = weapon:WaitForChild("Shoot")
		local FIRERATE = gunStats[weapon.Name]["FIRERATE"]
		
		-- // AUTOMATICS
		if weapon.GunType == gunStats[weapon.Name]["GUN_TYPE"] then
			mouse.Button1Down:Connect(function()
				if Shooting.Value then return end
				if Reloading.Value then return end
				if Bullets.Value < 1 then return end
				
				shooting = true
				local ShootAnim = animator:LoadAnimation(Shoot)
				ShootAnim:Play()
				ShootEvent:FireServer(mouse.Hit.Position)
				
				while shooting do
					if Bullets.Value < 1 then DisableIsHoldingEvent:FireServer() break end

					UpdateHitPosEvent:FireServer(mouse.Hit.Position)
					ShootAnim:Play()
					task.wait(FIRERATE)
				end
			end)
		end
	end		 
end)

char.ChildRemoved:Connect(function(child)
	if not child:IsA("Tool") then return end
	weapon = nil
end)

image

You need to do weapon.WeaponType.Value to read the value of the stringValue instance.

2 Likes

insert building collapsing gif

how did i overlook this, my god

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.