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.
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!