How do I make a functional 2D editor?

It would be so cool to have a 2D level editor and you can play it and upload it to a GUI menu. But because of the category rules, please only give help for parts of the scripts and not design the whole system.

Quick recap:

  • The editor which knows the input of the block the player has chosen and displays it.

  • A save button to upload it to another GUI menu.

That’s it. It’s not the whole system because there is more things I will include and I will figure out. I apologise for getting everyone into a mess.

3 Likes

Unfortunately, this is the Scripting Support forum.

We will help you with the code if you have any problems, but we won’t create systems for you, that’s not what this topic is about.

About the Scripting Support category:

Did he not say this, or what is going on?

I’m sure if OP can clarify what they need help with, then we can help with scripting/UI!

Unfortunately, fixing something that doesn’t exist is called creating.

I get you’re only asking for scripts but even something like this takes a while to explain and even longer to code. I recommend learning most about LuaU before trying this. You’ll have to only ask people some functions of your system and not how to make the whole system.

As for uploading them, I can’t help you there as I’ve never done anything similar, but I assume you would use DataStoreService for that.

But, for the actual editor: I’d use a 2D list of Tiles, where a Tile represents any tile you have. For instance:

type Tile
   = "Block"
   | "Damagebrick"
   | "Killbrick"
   ... and so on for all of your tiles ...

Then, display this to the player in some way that makes sense. E.g. Parts with ClickDetectors, ImageButtons, or another way that fits your game best. Either way, interacting with the visual representation of a value in the 2D list changes said value and the visual representation to the Tile the player has chosen.

For instance, let’s say we have two tiles: 0, and 1 (give yours better names obviously, this is an example)

[
    [0, 0, 0, 0],
    [0, 0, 0, 0],
    [0, 0, 0, 0],
    [0, 0, 0, 0],
]

Then, the player clicks the tile at [3][2], changing it to:

[
    [0, 0, 0, 0],
    [0, 0, 0, 0],
    [0, 0, 1, 0],
    [0, 0, 0, 0],
]

or something like that, depending on the setup of your game.

5 Likes

Thanks for the reply! This really helped but I have a question you don’t have to answer but would be helpful. How do I make the ClickDetectors change that part of the script? I only know Source but that changes the whole script. I am just a beginner at scripting and when I watch a tutorial of the basics, I forget in about 2-7 days.

1 Like

Assuming you have everything set up except for the ClickDetectors modifying the list, you can Connect the ClickDetector’s MouseClicked event to a function that modifies the list.

For instance,

local gameMapList = [
    [0, 0, 0, 0],
    [0, 0, 0, 0],
    [0, 0, 0, 0],
    [0, 0, 0, 0],
]

-- Replace this with your code
-- It should be a 2D list like gameMapList but with ClickDetectors
local gameMapClickDetectors = ...

for x = 1, #gameMapList do
    for y = 1, #gameMapList[x] do
        gameMapClickDetectors[x][y].MouseClicked:Connect(function()
            gameMapList[x][y] = selectedTileVariant -- e.g. "Killbrick"
        end)
    end
end

I haven’t tested this, but I think the general logic should work.

If you have any questions about this code or it doesn’t work, don’t hesitate to ask—I’ll try and help

1 Like

If I’m reading this right you want players to be able to create 2d levels and upload them? For creating the 2d levels I would base it off of scratch, where the players could code there own blocks to kill the player, make them jump, etc. or just give them already-made parts. If you are trying to display a block a player has chosen, you can just set a variable / value using text/image buttons, or allow them to simply drag and drop the “blocks” in.

I would make the “canvas” that players can insert blocks (frames) into a scrolling frame, which canvas size automatically sizes with the blocks the player inserts. This would making saving easy too, since all you would have to do it save the positions of every frame in that scrolling frame.

For collisions, you can try looking at this thread.

1 Like

I changed some bits of your code and it’s working well. All I need is an uploading system.

1 Like