Script can't see certain variable if else

function GunTakeOut()
	if action == true then
		return
	else
		action = true
	end
	lerpintensity = 0.3
	walking = false
	Character.Humanoid.WalkSpeed = 0
	if GunEquipped == false then
		for i = 1, 150 do
			wait()
			--anim
			elseif i >= 90 and i < 120 then
				GunWeld.Part0 = Character["Right Arm"]
				GunWeld.Part1 = Gun
				Gun.Parent = Character["Right Arm"]
				--animation
			--and then some more
		end
		action = false
		GunEquipped = true
		Character.Humanoid.WalkSpeed = 10
		GunIdleAnimation()
	else
		--animationthings
		action = false
		GunEquipped = false
		Character.Humanoid.WalkSpeed = 10
		IdleAnimation()
	end
end

The “animationthings” is just animation that works properly. The if, else, and elseif statements all work properly in this script. However, when the code is down here

action = false
GunEquipped = false
Character.Humanoid.WalkSpeed = 10
IdleAnimation()

it doesn’t really pick up a certain variable used earlier in the script: “Gun”. I want it to disappear, but the script can’t even touch it directly if I tell it to go into the arm it was parented to. I really don’t want to keep a gun in my hand and pretend I put it in my pocket, so can anyone tell me what’s wrong?

Tell me if you need more details.

Please put your code in between two ```'s so it’s easier to read. Like so:

image

print("Hello, World!")
1 Like

I had to do things with the variable BEFORE that part down there.