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 add to this number value?

It's hard scripting when tired. I need sleep.

local elevator = script.Parent.Parent.Move.BodyPosition
local Ready = script.Parent.Parent.Panel.Ready.Value
local Floor = script.Parent.Parent.Panel.Floor.Value
function Activate()
	if Floor >= 1 and Floor < 3 and Ready == true then
	Ready = false
	Floor = Floor + 1
	elevator.position = elevator.position + Vector3.new(0,32,0)
	wait(2)
	Ready = true
	

end
end

script.Parent.ClickDetector.MouseClick:connect(Activate)

`

"Floor" is a number value.

Every part of the script works but the adding part.

Edit: Odd, two things:

Ready value is also not changing,

the elevator is still not going beyond floor 3, despite the Floor value remaining the same.

2 answers

✓ Accepted answer

This is an incredibly common mistake.


Lines 2 and 3 accomplish almost nothing. The .Value property will evaluate to false / 0 (their default), so you just set the value false to Ready and Floor.

Later, changing those variables just changes those variables -- it isn't somehow linked to the values.


Solution: Use a variable to store the object, and explicitly modify its properties:

local Floor = script.Parent.Parent.Panel.Floor

...
if Floor.Value >= 1 and Floor.Value < 3 and Ready.Value then
	...

1 comment

0

Ah, I see. Thank you. That makes sense, and the elevator appears to be working now.

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