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

How can I change this BoolValue from inside a script?

Hi, I'm trying to make a system where there are 3 blocks that a team needs to touch and then a countdown will start.

The problem is that the bricks change colour when they're touched, like they're supposed to, but they don't seem to change the BoolValue I have set to true. The BoolValue is inside a part. The script I have for one of the points -

ValueA = game.Workspace.PartA.ValueA.Value
raidcolor = "Cool yellow"
defcolor = "Earth green"
script.Parent.Touched:connect(function(hit)
	if hit.Parent:findFirstChild("Humanoid") ~= nil then 
		if game.Players:GetPlayerFromCharacter(hit.Parent).TeamColor == BrickColor.new(raidcolor) then 
		ValueA=true
		script.Parent.BrickColor = BrickColor.new("Cool yellow")
		print 'a is capped'
	end
	end
end)
script.Parent.Touched:connect(function(hit)
	if hit.Parent:findFirstChild("Humanoid") ~= nil then 
		if game.Players:GetPlayerFromCharacter(hit.Parent).TeamColor == BrickColor.new(defcolor) then 
		ValueA=false
	script.Parent.BrickColor = BrickColor.new("Earth green")
	print 'a is uncapped'
		end
	end
	end)

Thanks, values not changing is fixed. New problematic code, where the timer will not start (sorry).

timer=1
totaltimer=1
ValueA = game.Workspace.PartA.ValueA
ValueB = game.Workspace.PartB.ValueB
ValueC = game.Workspace.PartC.ValueC
if ValueA.Value == true and ValueB.Value == true and ValueC.Value == true then
repeat
print'cool'
wait(1)
timer = timer + 1
until
timer > 3
if timer > 3 then
timer=totaltimer
end
game.Lighting.RaidersWin:Clone().Parent = game.Players.LocalPlayer.PlayerGui
for i, player in ipairs(game.Players:GetPlayers()) do
	if player.Character then
		local hum = player.Character:FindFirstChild('Humanoid')
		if hum then
			hum.Health = 0
			timer=totaltimer
			ValueA.Value=false
			ValueB.Value=false
			ValueC.Value=false
			game.Workspace.PartA.BrickColor.new=BrickColor.new"Earth green"
			game.Workspace.PartB.BrickColor.new=BrickColor.new"Earth green"
			game.Workspace.PartC.BrickColor.new=BrickColor.new"Earth green"
		end
	end
end
end

Thanks for reading!

3 answers

✓ Accepted answer

When you want to change a NumberValue BoolValue CFrameValue or anything like that and you want it to set a variable to it. You need to set the variable to the object ex:

ValueA = game.Workspace.PartA.ValueA

to access the value you would want

ValueA.Value

Your Problem

You're setting the 'ValueA' variable directly to the value of ValueA BoolValue. This makes the varaible equivelant to whatever value ValueA was when the code read it. You can't set the value like that..


How to Fix

Set the Variable to the BoolValue, then index the Value property when setting the value.


Code

I combined both of your Touched Events with an 'elseif' statement for efficiency

local ValueA = game.Workspace.PartA.ValueA
local raidcolor = "Cool yellow"
local defcolor = "Earth green"

script.Parent.Touched:connect(function(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	if plr then
		if plr.TeamColor == BrickColor.new(raidcolor) then
			ValueA.Value = true
			script.Parent.BrickColor = BrickColor.new(raidColor)
		elseif plr.TeamColor == BrickColor.new(defcolor) then
			ValueA.Value = false
			script.Parent.BrickColor = BrickColor.new(defcolor)
		end
	end
end)

2 comments

0

Thanks! This fixed half my problem. Sorry to bother again but I edited my post with a new issue.

0

Could you explain the problem with the second code and what it's expected to do?

Let's see

ValueA = game.Workspace.PartA.ValueA.Value
raidcolor = "Cool yellow"
defcolor = "Earth green"
script.Parent.Touched:connect(function(hit)
	if hit.Parent:findFirstChild("Humanoid") ~= nil then 
		if game.Players:GetPlayerFromCharacter(hit.Parent).TeamColor == BrickColor.new(raidcolor) then 
			ValueA=true
			script.Parent.BrickColor = BrickColor.new("Cool yellow")
			print 'a is capped'
		end
	end
end)
script.Parent.Touched:connect(function(hit)
	if hit.Parent:findFirstChild("Humanoid") ~= nil then 
		if game.Players:GetPlayerFromCharacter(hit.Parent).TeamColor == BrickColor.new(defcolor) then 
			ValueA=false
			script.Parent.BrickColor = BrickColor.new("Earth green")
			print 'a is uncapped'
		end
	end
end)

Let's zoom into one of your variables

ValueA = game.Workspace.PartA.ValueA.Value

You cannot assign a property to a variable.

Let's take a quick lookie

brickcolor = game.Workspace.BasePlate.BrickColor

brickcolor = BrickColor.new("Really red")

That code will not work because BrickColor isn't a child of BasePlate, but rather a property.

Your code actually works fine, that is if you didn't assign a property as a variable.

Replace

ValueA = game.Workspace.PartA.ValueA.Value

to

ValueA = game.Workspace.PartA.ValueA

and everytime you need to change the Value, you do this

ValueA.Value = value

1 comment

0

thanks a lot, that fixed most of my problem. The values change! :D. Sorry for the other question, but I edited my post with the new issue.

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