Reputation: 13
With the current complexity of scripting, and my abilities, i have hit a dead end with working out how to create a sliding door in the Popular MMO, "Roblox". I have analyzed the script automatically, and manually, and have not found any errors. Here it is below:
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)
When i have inserted a Button with a Clickdetector
inside, and tried to click the button, no results have been shown- not even an error! I am stuck, and require assistance. It would be much appreciated.
Upvotes: 1
Views: 1944
Reputation: 1
all you have to do is place a part in the workspace, rename it "Button" and insert a clickDetector into the part.
Upvotes: 0
Reputation: 56
Hmmm, works for me.
Is it already at (-61.866, 8.551, -97.181)?
Is there another "Part" or "Button"?
Is it not anchored and something in the way?
Alternate solution:
Put the button, part, and the following script together in a model.
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)
Hope that helps.
Upvotes: 1