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

My sliding door rotates then slides (I can't explain this in words) so please click! | ? |

Asked by 7 years ago
Edited 7 years ago

Hi, this is what i'm really stuck on: https://gyazo.com/614505fe67b3c3a5cb53c282217c5378

box = {"userdetail", "Jagyx"}

brick=game.Workspace["Viscull Siren"].siren.Folder
music=brick.Parent.music
local door = game.Workspace.door

local door2 = game.Workspace.door2


function onClicked(playerWhoClicked)
    for i = 1,60 do
        wait()
        door.CFrame = CFrame.new(door.Position + Vector3.new(0,-0.2,0))
        door2.CFrame = CFrame.new(door2.Position + Vector3.new(0,-0.2,0))    --[[That's the faulty door]]
    end
        if not music.Playing then
            for _,z in pairs(box) do
                 if game.Players.LocalPlayer.Name==z then
                    music:Play()
            end
        end
    end
end 
script.Parent.ClickDetector.MouseClick:connect(onClicked)

If anyone is able to help me, any response is useful (Sorry for the disgusting coding in advance xd) Again, any response is useful so please please reply! Thank you.

0
What am I supposed to look at, in the link? thesit123 509 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

I really recommend you use a CFrame function called lerp. More information about lerp can be found here in the Roblox Wiki: http://wiki.roblox.com/index.php?title=Lerp. What lerp does is it produces states between a start and an endpoint (The start point being represented by 0 and the end point being represented by 1). So what you can have it do is run a loop to go through all of the states just by using a start and an endpoint. In your case here what you would need to do is define your start and end points like so.

local startPoint = door.CFrame
local endPoint = door.CFrame:toWorldSpace(Vector3.new(0, -0.2, 0)) --This creates a CFrame using the doors CFrame, but adds an offet. In this case it's "Vector3.new(0, -0.2, 0)"

Now that we have our start and end points we just need to run a loop that goes from state to state until we are at the final state ending the animation.

for alpha = 0, 1, 0.001 do
    door.CFrame = startPoint:lerp(endPoint, alpha)
    wait()
end

What this loop here does is we define a variable called alpha which starts at 0 (our start point) and keeps looping until we reach 1 (our end point). Every time we loop we then increase alpha by 0.001. You can put whatever number you'd like there. Increasing it will increase the time it takes while making it smaller will make the animation slower. and that's simply it! If we include lerp in your script here's what it would look like.

box = {"userdetail", "Jagyx"}

brick=game.Workspace["Viscull Siren"].siren.Folder
music=brick.Parent.music
local door = game.Workspace.door

local door2 = game.Workspace.door2

local startPoint1 = door.CFrame
local startPoint2 = door2.CFrame
local endPoint1 = door.CFrame:toWorldSpace(Vector3.new(0, -0.2, 0))
local endPoint2 = door2.CFrame:toWorldSpace(Vector3.new(0, -0.2, 0))


function onClicked(playerWhoClicked)
    for alpha = 0, 1, 0.001 do
    door1.CFrame = startPoint1:lerp(endPoint1, alpha)
    door2.CFrame = startPoint2:lerp(endPoint2, alpha)
    wait()
    end
        if not music.Playing then
            for _,z in pairs(box) do
                 if game.Players.LocalPlayer.Name==z then
                    music:Play()
            end
        end
    end
end 
script.Parent.ClickDetector.MouseClick:connect(onClicked)

I hope this helps!

0
Thank you very much! userdetail 1 — 7y
0
Don't forget to accept this as the answer :) thebootsie123 160 — 7y
Ad

Answer this question