Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do you change the value object in a script?

--blue screen detection
script:WaitForChild("COMP1")
script:WaitForChild("COMP2")
script:WaitForChild("COMP3")
script:WaitForChild("CurrentComp")

local CurrentComp = script.CurrentComp
local Comp1 = script.COMP1
local Comp2 = script.COMP2
local Comp3 = script.COMP3

	if CurrentComp == 0 then
		print("Broken Value " .. CurrentComp.Value .. " : Not correct value for boot")
	elseif CurrentComp == 1 then
		
		print("Computer 1 is accessed")
		if script.COMP1.Value == true then
			print("Blue screen computer 1")
			script.Parent.BlueBoot.Value = true
		else
			print("Normal Boot for computer 1")
			script.Parent.BlueBoot.Value = false
		end
		
	elseif CurrentComp == 2 then
		
		print("Computer 2 is accessed")
		if script.COMP2.Value == true then
			print("Blue screen computer 2")
			script.Parent.BlueBoot.Value = true
		else
			print("Normal Boot for computer 2")
			script.Parent.BlueBoot.Value = false
		end
		
	elseif CurrentComp == 3 then
		
		print("Computer 3 is accessed")
		if script.COMP3.Value == true then
			print("Blue screen computer 3")
			script.Parent.BlueBoot.Value = true
		else
			print("Normal Boot for computer 3")
			script.Parent.BlueBoot.Value = false
		end
		
	end

That script is determining if a computer is actually bootable or if it needs a blue screen to appear. I have value objects such as numerical values and boolean values. My script will fire on a filter enabled which I will add later but the things is that this should auto output the first print because the number value is 0 on default.

if CurrentComp == 0 then
		print("Broken Value " .. CurrentComp.Value .. " : Not correct value for boot")

That right above this should fire the output "Broken value 0: Not correct value for boot" But nothing shows up in output.

Thanks for the help!

1 answer

✓ Accepted answer

Only problem I see is in your variable declaration

First problem is you are setting the variables to actual objects and not their values, so when you check for CurrentComp==0, it won't work, so all you need to do is:

local Comp1 = script:WaitForChild("COMP1")
local Comp2 = script:WaitForChild("COMP2")
local Comp3 = script:WaitForChild("COMP3")
local CurrentComp = script:WaitForChild("CurrentComp").Value

The second thing which is not a problem, but can be written better, is that when you WaitForChild, it will return the child when or if it is found, which simplifies the top 8 lines of your code.

This discussion is preserved as it was. New answers, comments, and votes are closed.