Script not working for some reason

So i made a railgun. It has a battery, coolant, reloading and broken system ( Meaning its very realistic ) All the features work fine, except for the firing system. I have values in workspace to tell if everything is on. heres my code:

local closeAnim = require(game.Workspace.door.Animator) 
local debounce = false
local g1 = game.Workspace.gen1.Value
local g2 = game.Workspace.gen2.Value
local g3 = game.Workspace.gen3.Value
local reloaded = game.Workspace.reloaded.Value
local broken = game.Workspace.broken.Value
local coolant = game.Workspace.coolantValue.Value
local rocket = game.ServerStorage.Rocket

function onClicked(playerWhoClicked)
	script.Parent.Transparency=1
	if g1 and g2 and g3 and reloaded and coolant then
		print("ready to fire")
		if broken == false then
			local clone = rocket:Clone()
			local brokenChance = math.random(0,4)
			clone.Parent = game.Workspace
			game.ReplicatedStorage.CameraShake:FireAllClients()
			game.Workspace["Wind Whoosh Sonic Boom Low End Impact 2 (SFX)"]:Play()
			game.Workspace["Big Explosion"]:Play()
			closeAnim.NewTween1:Play()
			reloaded = false
			if brokenChance == 2 then
				broken = true
				game.ServerStorage.Fire.Parent = game.Workspace
				game.Workspace.brokenPart.ProximityPrompt.Enabled = true
			end
			
			
			
		else
			script.Parent.ProximityPrompt.ActionText = "Component not on or broken"
			wait(2)
			script.Parent.ProximityPrompt.ActionText = "Fire"
		end
		
		
	end
	wait(.1)
	script.Parent.Transparency=0
end
script.Parent.ProximityPrompt.Triggered:Connect(onClicked)

its not even printing the “ready to fire”
my theory is that somethings wrong with the first if statement. i dont know how to use ands so i just decided to wing it( i dont even know if ands are a thing ). perhaps thats the problem?

1 Like

I’m pretty sure it’s because in the variables you’re immediately getting the Value and storing it, so any changes wont show up in the variables, remove the .Value from all the variables and when you refer to a variable that had that, put .Value infront of it,

Example

local g1 = game.Workspace.gen1
local g2 = game.Workspace.gen2
local g3 = game.Workspace.gen3
local reloaded = game.Workspace.reloaded
local coolant = game.Workspace.coolantValue

if g1.Value and g2.Value and g3.Value and reloaded.Value and coolant.Value then
    print("Ready to fire")
end
1 Like

I know you didnt ask, but i have this thing engraved in my head telling me variables holding bool values change when the value changes. I actually was actually going to do what you suggested but i thought it was to messy. Anyways it worked! Thanks a lot!

1 Like

It doesn’t only do that with bool values, that’s why I almost never store the value of a Bool/Int/Number/String value directly in a variable I rather just store the instance and access their .Value when I need it, that way I can actually change the value and not the variables value and get all the current values

1 Like