I am making an elevator script and am using an IntValue to determine which floor the elevator is on. However, when I click a button to go to a floor, the IntValue doesn’t change to said floor number even though it is set to do so.
local FloorNumber = script.Parent.Parent.FloorNumber.Value
and local FloorNumber = 2
When the script with the “local FloorNumber = 2” is ran, the IntValue never actually changes to 2. Anyone have any idea what’s wrong?
The problem here is this: local FloorNumber = script.Parent.Parent.FloorNumber.Value
If you put .Value there, it only taking the value of intValue but if you change it, it won’t effect the intValue and only effect the FloorNumber variable.
Second problem is that you put is: local FloorNumber = 2
You shouldn’t put another local, only put it once unless you want to make a new variable.
Here’s the code to make it work properly: local FloorNumber = script.Parent.Parent.FloorNumber FloorNumber.Value = 2
Actually I missed something important. Before that line is FloorNumber > 2
but roblox does not like that because of the fact that I’m comparing an instance and a number. I use that line in an if statement btw.
Oh I see, up there you have the IntValue’s Value property assigned to that variable. Which means It’s pretty much the same as doing FloorNumber.Value.Value, I am kind of confused can you show me your variables if you could please?
Screw it. Here’s my entire code lol. The FloorNumber variable is the IntValue variable
-- Made by Overglocked
-- The floor 1 button script is a bit different from the other scripts due to reasons I'm not sure how to explain. Just don't ask.
-- Note: Must have NumberValue called "FloorNumber" in the model
local elevatorFloor = script.Parent.Parent.Floor
local ClickDetector = script.Parent.ClickDetector
local FloorNumber = script.Parent.Parent.FloorNumber
-- Floor list. For every floor you make, place a part that is the same size as the elevator floor and has the same cordinates except for the y cordinate. Ex: If the elevator floor's position is 0(0,0,0) then the new cordinates would be (0,5,0) to make it directly above the floor
-- Ex: local floor2 = game.Workspace.Floor2Position.Position
local Floor1Pos = script.Parent.Parent.Floor1Location.Position
local Floor2Pos = script.Parent.Parent.FL2cords.Position
local Floor3Pos = script.Parent.Parent.FL3cords.Position
--End of list but can be extended for every floor
local function elevator()
if FloorNumber == 2 then -- Change the "1" to whatever floor the button goes to. Ex: If the button goes to floor 2, then change the "1" to 2
-- If the elevator is already on the designated floor
print("Didn't change floors due to the elevator already being on the selected floor.")
elseif
FloorNumber.Value < 2 then -- If elevator is below designated floor
FloorNumber = 2
while true do
local elevatorPos = elevatorFloor.Position -- COPY THIS TO BOTH SCRIPTS THAT MAKE THE ELEVATOR GO DOWN AND UP
elevatorFloor.CFrame = CFrame.new(elevatorFloor.Position + Vector3.new(0,0.5,0))
wait()
if elevatorPos == Floor2Pos then -- Switch the Floor pos variable to whatever floor the button correct. MAKE SURE THAT THIS LINE OF CODE IS COPIED FOR THE SCRIPTS THAT MAKE THE ELEVATOR GO DOWN AND UP. Change variable to whatever floor position you need.
break
else
if FloorNumber.Value > 2 then -- If elevator is above designated floor
FloorNumber = 2
while true do
local elevatorPos = elevatorFloor.Position
elevatorFloor.CFrame = CFrame.new(elevatorFloor.Position - Vector3.new(0,0.5,0))
wait()
if elevatorPos == Floor2Pos then
break
end
end
end
end
end
end
end
ClickDetector.MouseClick:Connect(elevator)
Ok sorry this has been going on for so long now. I realize that I’m a braindead in scripting. But anyways, the new changes now cause the output to error and say “attempt to index number with ‘value’”. Not exactly sure what roblox wants if it’s not that
You’re basically re-writing the variable FloorNumber and then when you want to check for it’s value, 2 is a number and not an instance that has the property “Value”.
The solution would be to change all the FloorNumber = 2 to FloorNumber.Value = 2.