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

What is happening with my script for Update log? [Cleaned code]

Asked by 9 years ago

Basically there are two parts which have similar names that can be found in variables in my script. These two parts contain SurfaceGui's. One of these has a TextButton and a TextLabel inside of a Frame. The actual Update log is just a Part that has a SurfaceGui and multiple TextLabels to put in words. This part starts in the ground(Out of sight) and you must press the TextButton to have it rise out of the ground then stop and the TextLabel will have changed words. Then, pressing the TextButton again causes the Update log to lower back inside of the ground, with the TextLabel's words changing.

Now, it appears everything but the CFraming part of my script works. I think I might be using the wrong for loop, or using it incorrectly. I will explain problems at the bottom(Under Script)

This is the script(It's the Child of TextButton that must be clicked):


--Closed-- 213, 169.4, 62 -- I just put the position that is in properties when closed --Opened-- 213, 180.4, 62 -- Same as Above, but when opened --Press to view Update Log -- Starting Text for TextLabel script.Parent.MouseButton1Click:connect(function() local UL = game.Workspace.UpdateLog -- This is rising out of ground local ULB = game.Workspace.UpdateLogButton.ControlGUI.Core.Desc if UL.Status.Value == "Closed" then for i = 169.4,180.4, 0.1 do UL.CFrame = UL.CFrame * CFrame.new(0,i,0) UL.Status.Value = "Opened" ULB.Text = "Press to close Update Log" end elseif UL.Status.Value == "Opened" then for i = 180.4,169.4, -0.1 do UL.CFrame = UL.CFrame * CFrame.new(0,i,0) UL.Status.Value = "Closed" ULB.Text = "Press to view Update Log" end end end)

Now, before I click any buttons while in test mode, this is it's current position 213, 169.4, 62 Now, I clicked the TextButton 1 time and this is it's new position 213, 19583.301, 62 Here is the second click 213, 38997.199, 62 My StringValue is changing from Opened to Closed every click. I hope I gave a MUCH better code( Even though it's not functioning correctly ) and better description.

Everything BUT CFrame seems to be working correctly. No Errors in Output

0
Just do UL.CFrame = CFrame.new(UL.CFrame.X,i,UL.CFrame.Z) EzraNehemiah_TF2 3552 — 9y
0
LordDragonZord , This moves it to the correct position. The problem is that it's instantly AND the part is turned around 180Degrees; causing it to face away from viewer. I would like it to Rise smoothly out of the ground and face the correct position. I don't know how your change flipped it? alphawolvess 1784 — 9y

1 answer

Log in to vote
1
Answered by
duckwit 1404 Moderation Voter
9 years ago

CFrame

When you compute UL.CFrame * CFrame.new(0,i,0), the output will be the current value of UL.CFrame, but with an offset of (0,i,0), when actually you want the position vector of the output CFrame to have the form (x,i,z) (where x and z are the current positions for those axes).

LordDragonZord suggested that you try UL.CFrame = CFrame.new(UL.CFrame.X,i,UL.CFrame.Z), but this is only true for a specific case; his version would work only if UL has a rotation matrix of (1,0,0,0,1,0,0,0,1). To preserve the orientation, you'll want to use:

local previous = UL.CFrame
UL.CFrame = previous  * CFrame.new(0, i - previous.p.Y,0)

In words: The new CFrame will be the previous CFrame value translated by the difference between the current y-axis position and the desired y-axis position.

Animation

To make it happen smoothly, or rather, in small increments, all you need to do is add a call to the wait() function inside each of the for loops.

for i = 169.4,180.4, 0.1 do
    UL.CFrame = UL.CFrame * CFrame.new(0,i,0)
    UL.Status.Value = "Opened"
    ULB.Text = "Press to close Update Log"
    wait()
end
0
Thank you. It's bothersome how different CFrame is compared to Position, lol. alphawolvess 1784 — 9y
Ad

Answer this question