Robbery System doesn't seem to work with bool values

So i’m working on a robbery system, but i encountered an issue.

So i’m using bool values to indicate if the C4 is armed or not, somehow when the bool values are set to true the C4 doesn’t start.

Screenshots



image

At this point i’m using devforum as my last resort, currently i did get some answers but still no luck.
So here’s the code if you want to see it.

local C4_Model = script.Parent.EnableParts
local Prompt = script.Parent.C4_Interact.RangePart:WaitForChild("ProximityPrompt")

--//Starting The C4
local SwitchPrompt = script.Parent.C4_Arm.RangePart:WaitForChild("ProximityPrompt")

function Beep()
	script.Parent.Lamp.Flash.Enabled = true
	script.Parent.Lamp.PL.Enabled = true
	script.Parent.Lamp.Beep:Play()
end

function Plant()
	script.Parent.C4_Interact.Plant:Play()
	for i, v in pairs(C4_Model:GetChildren()) do
		if v.Name == 'On' then
			v.Transparency = 1
		else
			v.Transparency = 0
		end
		script.Parent.HUD.SurfaceGui.Enabled = true
	end
end

function ArmC4()
	script.Parent.C4_Arm.Switch:Play()
end

Prompt.Triggered:Connect(function()
	script.Parent.C4isPlanted.Value = true
	Plant()
	Prompt.Enabled = false
	SwitchPrompt.Enabled = true
end)

SwitchPrompt.Triggered:Connect(function()
	ArmC4()
	SwitchPrompt.Enabled = false
	script.Parent.C4isArmed.Value = true
	script.Parent.HUD.SurfaceGui.TextLabel.Text = "ARMED!"
end)

if script.Parent.C4isArmed.Value == true then
	Beep()
	wait(0.5)
	Beep()
	wait(0.5)
	Beep()
	wait(0.4)
	Beep()
	wait(0.4)
	Beep()
	wait(0.3)
	Beep()
	wait(0.3)
	Beep()
	wait(0.2)
	Beep()
	wait(0.2)
	Beep()
	wait(0.1)
	Beep()
	wait(0.1)
end

Not sure but i think it’s because your making it only check once if it’s true so it prob runs even when it’s false once so try using runservice.renderstepped to check infinitely if it’s true ig or do a while true loop so it can check always if it’s true these 2 can work ig

This only runs ONCE, when the script gets loaded. Instead you want to update the script.

local isArmed = script.Parent.C4isArmed
isArmed.Changed:Connect(function()
   if isArmed .Value == true then
      ... -- code here
   end
end)
1 Like

Not essential but looks nicer…

local waittime = 5
repeat
    Beep()
    task.wait(math.ceil(waittime) / 10)
    waittime -= 0.5
until waittime == 0

Still, no luck from that. It’s been a while since i’ve started scripting, almost forgot everything. But i appreciate the reply.

I think Devs are suggesting that you should listen when the Bool Value changes actively, connecting a Changed event to the value, to listen when it changes to true or false, and rebuild your your “repeat logic”, merging what @Wigglyaa and @KJry_s suggested with your code could be.

Its just a basic example, could be done better, edit it to your needs:

local C4_Model = script.Parent.EnableParts
local Prompt = script.Parent.C4_Interact.RangePart:WaitForChild("ProximityPrompt")

--//Starting The C4
local SwitchPrompt = script.Parent.C4_Arm.RangePart:WaitForChild("ProximityPrompt")

function Beep()
	script.Parent.Lamp.Flash.Enabled = true
	script.Parent.Lamp.PL.Enabled = true
	script.Parent.Lamp.Beep:Play()
end

function Plant()
	script.Parent.C4_Interact.Plant:Play()
	for i, v in pairs(C4_Model:GetChildren()) do
		if v.Name == 'On' then
			v.Transparency = 1
		else
			v.Transparency = 0
		end
		script.Parent.HUD.SurfaceGui.Enabled = true
	end
end

function ArmC4()
	script.Parent.C4_Arm.Switch:Play()
end

Prompt.Triggered:Connect(function()
	script.Parent.C4isPlanted.Value = true
	Plant()
	Prompt.Enabled = false
	SwitchPrompt.Enabled = true
end)


---
local Debounce = false
local isArmed = script.Parent.C4isArmed -- The value to listen

-- Timer loop
local function Start(timer)
	for c = timer, 0, -1 do
		warn(c)
		Beep() -- call your beep()
		task.wait(1) -- wait 1 second per iteration
	end
end

-- listening when C4isArmed value changes:
isArmed.Changed:Connect(function(newVal)
	if newVal and not Debounce then -- if bool value is true and C4 not used yet
		Debounce = true -- used
		Start(5) -- start timer 5 seconds
	end
end)
---


SwitchPrompt.Triggered:Connect(function()
	ArmC4()
	SwitchPrompt.Enabled = false
	isArmed.Value = true
	script.Parent.HUD.SurfaceGui.TextLabel.Text = "ARMED!"
end)
1 Like

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