Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can i add to this number value?

Asked by 9 years ago

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

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

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
    ...
0
Ah, I see. Thank you. That makes sense, and the elevator appears to be working now. Maxwell_Edison 105 — 9y
Ad
Log in to vote
-1
Answered by
zub74 0
9 years ago

Post as a lua bracket, please

0
thought I did. Done. Maxwell_Edison 105 — 9y

Answer this question