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

How would I go about making certain objects appear at the same and certain time?

Asked by 6 years ago
Edited 6 years ago

What I am trying to do is if two or more objects hold the same 'value' (seconds), they should appear, or in this case, come down at the same `time'. I am almost happy with the result but it is not quite there, yet. Both the module and localscripts are provided below

ModuleScript

--Module: Map_Encoded
--This is in the module. I provided 100 objects as my module holds more than 1,000
return {--[[
     Position,  Seconds]]
[1] = {0.063, 0.4811924769908},
[2] = {0.126, 0.4811924769908},
[3] = {0.252, 0.4811924769908},
[4] = {0.063, 0.6952781112445},
[5] = {0.252, 0.6952781112445},
[6] = {0.126, 0.9093637454982},
[7] = {0.252, 0.9093637454982},
[8] = {0.063, 1.124449779912},
[9] = {0.252, 1.124449779912},
[10] = {0.126, 1.3385354141657},
[11] = {0.252, 1.3385354141657},
[12] = {0.126, 1.7677070828331},
[13] = {0.252, 1.7677070828331},
[14] = {0.126, 1.9817927170868},
[15] = {0.252, 1.9817927170868},
[16] = {0.126, 2.1958783513405},
[17] = {0.252, 2.1958783513405},
[18] = {0.063, 2.4099639855942},
[19] = {0.189, 2.4099639855942},
[20] = {0.126, 2.625050020008},
[21] = {0.252, 2.625050020008},
[22] = {0.063, 2.8391356542617},
[23] = {0.252, 2.8391356542617},
[24] = {0.126, 3.0532212885154},
[25] = {0.252, 3.0532212885154},
[26] = {0.126, 3.4823929571829},
[27] = {0.252, 3.4823929571829},
[28] = {0.063, 3.6964785914366},
[29] = {0.252, 3.6964785914366},
[30] = {0.252, 3.9105642256903},
[31] = {0.189, 3.9105642256903},
[32] = {0.189, 4.125650260104},
[33] = {0.252, 4.125650260104},
[34] = {0.063, 4.3397358943577},
[35] = {0.189, 4.3397358943577},
[36] = {0.126, 4.5538215286114},
[37] = {0.252, 4.5538215286114},
[38] = {0.252, 4.7689075630252},
[39] = {0.189, 4.7689075630252},
[40] = {0.063, 5.1970788315326},
[41] = {0.252, 5.1970788315326},
[42] = {0.126, 5.4111644657863},
[43] = {0.252, 5.4111644657863},
[44] = {0.252, 5.6262505002001},
[45] = {0.126, 5.6262505002001},
[46] = {0.252, 5.8403361344538},
[47] = {0.063, 5.8403361344538},
[48] = {0.126, 6.0544217687075},
[49] = {0.252, 6.0544217687075},
[50] = {0.063, 6.2695078031212},
[51] = {0.252, 6.2695078031212},
[52] = {0.126, 6.4835934373749},
[53] = {0.252, 6.4835934373749},
[54] = {0.063, 6.9117647058824},
[55] = {0.252, 6.9117647058824},
[56] = {0.189, 7.1268507402961},
[57] = {0.252, 7.1268507402961},
[58] = {0.126, 7.3409363745498},
[59] = {0.252, 7.3409363745498},
[60] = {0.063, 7.5550220088035},
[61] = {0.063, 7.5550220088035},
[62] = {0.126, 7.7701080432173},
[63] = {0.063, 7.7701080432173},
[64] = {0.189, 7.984193677471},
[65] = {0.252, 7.984193677471},
[66] = {0.063, 8.1982793117247},
[67] = {0.252, 8.1982793117247},
[68] = {0.252, 8.6274509803922},
[69] = {0.063, 8.6274509803922},
[70] = {0.189, 8.8415366146459},
[71] = {0.126, 8.8415366146459},
[72] = {0.252, 9.0556222488996},
[73] = {0.189, 9.0556222488996},
[74] = {0.189, 9.2707082833133},
[75] = {0.252, 9.2707082833133},
[76] = {0.252, 9.484793917567},
[77] = {0.063, 9.484793917567},
[78] = {0.063, 9.6988795518207},
[79] = {0.126, 9.6988795518207},
[80] = {0.063, 9.9129651860744},
[81] = {0.063, 9.9129651860744},
[82] = {0.252, 10.342136854742},
[83] = {0.063, 10.342136854742},
[84] = {0.126, 10.556222488996},
[85] = {0.252, 10.556222488996},
[86] = {0.252, 10.771308523409},
[87] = {0.189, 10.771308523409},
[88] = {0.063, 10.985394157663},
[89] = {0.189, 10.985394157663},
[90] = {0.126, 10.985394157663},
[91] = {0.252, 11.199479791917},
[93] = {0.189, 11.41356542617},
[94] = {0.252, 11.41356542617},
[96] = {0.126, 11.628651460584},
[98] = {0.252, 12.056822729092},
[99] = {0.126, 12.271908763505},
[100] = {0.252, 12.271908763505},
}

LocalScript

local map_encoded = require(script.Parent:FindFirstChild("Map_Encoded") or script.Parent:WaitForChild("Map_Encoded"))
local note_i = 1 --Although not necessary, but helps when "note[2] (0.481) hits"

function create_note(pos)
    local note = Instance.new("ImageLabel");
    note.Size = UDim2.new(0.063, 0,0.011, 0);
    note.Position = UDim2.new(pos, 0, 0, 0);
    note.BorderSizePixel = 0
    note.ZIndex = 3
    note.BackgroundColor3 = Color3.new(255/255, 255/255, 255/255)
    note.Parent = script.Parent
end

local start_tick = tick() --Usually left as "nil" but when the function is called the 'tick' would be set.
for i = 1, #map_encoded * #map_encoded --[[Decided to multiply so it can at least last]] do
    local end_tick = tick()
    local note = map_encoded[note_i]
    local current_time = end_tick - start_tick
    --print(note[2] <= current_time, "-::-", note[2])

    --[[note[1] = position
        note[2] = seconds or time]]
    if note[2] <= current_time then
        create_note(note[1])
        for ip, v in pairs(script.Parent:GetChildren()) do
            if v:IsA("ImageLabel") then
                v:TweenPosition(UDim2.new(v.Position.X.Scale, 0, .788, 0), "Out", "Linear")
            end
        end
        note_i = note_i + 1
    end
    game:GetService("RunService").RenderStepped:wait()
end

I do have an old method way of doing this but that method is inefficient, performance wise. Showing another method would be nice as this was the only thing I could think of.

0
Do you not know what 255/255 is? You should know, it is not necessary. Do you know what Color3.fromRGB is? hiimgoodpack 2009 — 6y
1
They both work. It's really just developer preference Thundermaker300 554 — 6y

Answer this question