Mr. CFrame, meet a bunch of numbers.
As you said in Chat, it is not moving, at all.
That is because you are comparing CFrame with a bunch of Numbers.
First, let's discuss:
CFrames are not a bunch of numbers, but rather userdata.
Userdata is data structures.
Now that we got that out of the way, why does your script not work?
It's because, like I said, CFrames are not numbers.
local part = script.Parent
local w = workspace
local door = w.ddd
script.Parent.ClickDetector.MouseClick:connect(function()
if door.CFrame == CFrame.new(22.37, 5.115, -37.9) then
door.CFrame = door.CFrame * (CFrame.new(25, 10, -40))
elseif door.CFrame == CFrame.new(25, 10, -40) then
door.CFrame = door.CFrame * (CFrame.new(22.37, 5.115, -37.9))
end
end)
In your code, you are seen comparing CFrames, or are you?
You are actually comparing CFrames to Numbers
print(CFrame.new(1337, 360, 420) == (1337,360,420))
print(CFrame.new(1337,360,420) == CFrame.new(1337,360,420))
Why does the second one return true? Is it because it's longer?
No, it's actually because we are comparing the correct data types now.
We are comparing CFrames with CFrames!
Now let's fix that code of yours.
local part = script.Parent
local w = workspace
local door = w.ddd
script.Parent.ClickDetector.MouseClick:connect(function()
if door.CFrame == CFrame.new(22.37, 5.115, -37.9) then
door.CFrame = door.CFrame * (CFrame.new(25, 10, -40))
elseif door.CFrame == CFrame.new(25, 10, -40) then
door.CFrame = door.CFrame * (CFrame.new(22.37, 5.115, -37.9))
end
end)
Well, it turns out your edit fixed that error, crap
From what I see the only error here is that Roblox's program cannot compare Floats correctly.
Floats are numbers, with decimals, such as 123.51241
With computers, it is hard to compare floats, because they are specific.
To fix that, round all your CFrames into wholes like
local part = script.Parent
local w = workspace
local door = w.ddd
script.Parent.ClickDetector.MouseClick:connect(function()
if door.CFrame == CFrame.new(22,5 , -37) then
door.CFrame = (CFrame.new(25, 10, -40))
elseif door.CFrame == CFrame.new(25, 10, -40) then
door.CFrame = (CFrame.new(22, 5 -37))
end
end)
###If this doesn't work, then I have no idea.###
1 comment
(just so you get the notification) The script isn't printing an error but it is also not doing anything. My script matches both of yours and it's not moving the brick.