Lua Roblox Studio脚本中的C框架滑动门

Lua Roblox Studio脚本中的C框架滑动门,lua,roblox,Lua,Roblox,鉴于目前脚本编写的复杂性和我的能力,我在研究如何在流行的MMO“Roblox”中创建滑动门时遇到了死胡同。 我已经自动和手动分析了脚本,没有发现任何错误。 以下是: local Part = workspace.Part local newPos = Part.Position + Vector3.new(-61.866, 8.551, -97.181) local Time = 5 local Increment = 0.5 local Debounce = false local Dif

鉴于目前脚本编写的复杂性和我的能力,我在研究如何在流行的MMO“Roblox”中创建滑动门时遇到了死胡同。 我已经自动和手动分析了脚本,没有发现任何错误。 以下是:

local Part = workspace.Part
local newPos = Part.Position + Vector3.new(-61.866, 8.551, -97.181)
local Time = 5
local Increment = 0.5 
local Debounce = false

local Diff = newPos - Part.Position
local Mag = Diff.magnitude
local Direction = CFrame.new(Part.Position, newPos).lookVector

function MovePart()
if Debounce then return end
    Debounce = true
    for n = 0, Mag, Increment do
        Part.CFrame = Part.CFrame + (Direction * Increment)
        wait( (Time/Mag) * Increment )
    end
    Debounce = false
end

workspace.Button.ClickDetector.MouseClick:connect(MovePart)
当我插入一个内部带有
Clickdetector
的按钮并尝试单击该按钮时,没有显示任何结果-甚至没有错误!我陷入困境,需要帮助。非常感谢。

嗯,对我有用。
它已经在(-61.866,8.551,-97.181)了吗?
是否还有其他“部件”或“按钮”?
它不是被锚定了吗

替代解决方案:
将按钮、零件和以下脚本放在一个模型中

local Part = script.Parent.Part
local Button = script.Parent.Button
Part.Anchored = true
local Direction = Part.CFrame.lookVector
local Mag = Part.Size.Z

local Time = 5
local Increment = 0.5 -- Smaller will make smoother 'movement'
local Debounce = false

function MovePart()
if Debounce then return end
    Debounce = true
    for n = 0, Mag, Increment do
        Part.CFrame = Part.CFrame + (Direction * Increment)
        wait(Time/(Mag * Increment))
    end
    for n = 0, Mag, Increment do
        Part.CFrame = Part.CFrame + (Direction * -Increment) -- so that it moves back
        wait(Time/(Mag * Increment))
    end
    Debounce = false
end

clickD = Button.ClickDetector or Instance.new("ClickDetector",Button)
clickD.MouseClick:connect(MovePart)

希望这会有所帮助。

您所要做的就是在工作区中放置一个零件,将其重命名为“Button”,然后在零件中插入一个clickDetector