#Need help with a sliding puzzle

1 messages · Page 1 of 1 (latest)

severe merlin
#

Hello im making a project and one of the puzzles im making is a sliding puzzle however its having a problem that i dont know how to fix basically when i click play it works and all being able to move the pieces but the main problem is that it spawns in a complete different place from where it shows in studio when i click play, and if i move it manually it breaks and it shows it completed and you cant touch anything. Any help? here is the script

#

and here is the problem of where it spawns

severe merlin
#

i believe it has to be with the vector but i dont really know anyone can help :c?

errant crown
#

Can you post the code as a code block instead of images?

fallen viper
#

send me a code

severe merlin
#

sorry my timezone is different

#

thats why i replied late

errant crown
# severe merlin

I dont have a good luau viewer on my phone, so i asked deepseek to just write it in its app code viewer 🫠, but it tought this

#

U are missing a function in the txt file 🫠

severe merlin
#

huh oh

#

weird cause roblox studio doesnt show an error in the script

errant crown
#

The only thing i can think of is that the model pivot point is in the middle of nowhere

#

At somepoint you use model:moveTo() or model:PivotTo() and that causes unexpect behavoiur

severe merlin
#

oh whoops idk why is it at 4,4,1

errant crown
#

Yeah that, try setting the pivot offset to zero and no primary part

#

Or just using a folder instead of a model

severe merlin
#

aight done let me try moving it

#

eh the script makes it spawn somewhere else instead of where i put it in studio

severe merlin
#

well idk whats causing this

#

atp ill just manually change the position from the script myself

errant crown
# severe merlin eh the script makes it spawn somewhere else instead of where i put it in studio

The positioning is relative to the workspace origin rather than the puzzle model due to how the Position property is set and the coordinate system used. Here's why:

  1. Absolute Positioning:

    tile.Position = Vector3.new((x - 85) * tileSize, tile.Position.Y, (y + 57) * tileSize)
    
    • This sets the tile's position in world space (workspace coordinates)
    • The calculation doesn't reference puzzleModel's position, making it absolute rather than relative
  2. Coordinate System:

    • Roblox parts use workspace coordinates by default when setting .Position
    • To position relative to the model, you'd need to:
      1. Get the model's CFrame (position + orientation)
      2. Convert local positions to world space using modelCFrame * Vector3.new(x, y, z)
  3. Offsets Explained:

    • (x - 85) and (y + 57) are hardcoded offsets
    • These likely place the puzzle grid in a specific location in the workspace
    • For a 5x5 grid (gridSize=5), this centers tiles around:
      • X: (3 - 85)*4 = -328 (since middle tile x=3)
      • Z: (3 + 57)*4 = 240
  4. Why it works:

    • The tiles are children of puzzleModel, but their positions are set in world space
    • When the model moves, its children move with it (inheriting transform)
    • The initial positions are calculated relative to world origin, not model origin

To make it relative to the model, you'd need to:

  1. Add a reference part in the model (e.g., PuzzleOrigin)
  2. Modify setTilePosition:
    local origin = puzzleModel.OriginPart.Position
    tile.Position = origin + Vector3.new((x-3)*tileSize, 0, (y-3)*tileSize)
    
    (Where 3 is half of gridSize=5 for centering)

The current approach is simpler but assumes:

  • The model starts at a known position
  • No rotation is applied to the model
  • Tile Y-positions are preserved from their original placement
errant crown
errant crown
errant crown
#

Instead of being relative to the model

#

I tought his problem was that it was being placed in the wrong hardcoded position

south nexus
severe merlin
#

so then

south nexus
#

oh nvm there are hardcoded coords, the image and the code are different

severe merlin
#

i can record myself in any case to show what happens when i click play and when i move it manually

south nexus
#

the ai explained this

severe merlin
#

yeah i know if i move the model manually once i click play it just breaks

south nexus
#

one of the few occasions where it is correct

severe merlin
#

but if i leave it where it is, it spawns somewhere else

#

so ill just change the position inside the script

#

in studio it will show somehwere else but in game it will show where i want

south nexus
#

it doesnt matter where you put it in studio ?

severe merlin
#

it does

#

if i put it where i want it to be then hit play

south nexus
severe merlin
#

the puzzle is shown completed

#

and you cant move anything

south nexus
#

i mean in its current state

severe merlin
#

i just told u

south nexus
south nexus
severe merlin
#

it works perfectly if i dont move it

south nexus
#

server script or localscript?

severe merlin
#

local

south nexus
#

thought so, so yea ai not gonna pick up on that unless you know to ask. the parts dont exist yet on the client when this code runs. workspace instance streaming

severe merlin
#

see

#

if i change it manually from the script it works

#

if i move it from studio it breaks

#

honestly i dont mind if it shows somewhere else in studio

south nexus
#

set the model's streamingmode to atomic

severe merlin
south nexus
#

persistent would also work

#

i prefer atomic personally

severe merlin
#

huh WHAT it worked

#

like i moved it without the script and its there and it works

#

wow Tysm

south nexus
#

wait for it...

errant crown
severe merlin
south nexus
#

unless you already fixed the other 2 problems

severe merlin
#

i did

#

thats the only thing annoying me

#

the position between play and studio

south nexus
#

yea that was 2 fold, one was instance streaming the other was hardcoded positions, and then you have clicks not working

severe merlin
#

anyway thank you a lot both of u

distant lanceBOT
#

studio** You are now Level 5! **studio

south nexus
errant crown
south nexus
errant crown
south nexus
#

there are far more beginners than there are experts.

errant crown
errant crown
#

In a scale from 1 to 10

south nexus
#

depends on your code, if you want to config that way it's fine. the only sin i see is Stadistics

errant crown
south nexus
#

skill issue

errant crown
# south nexus skill issue

I mean, it cant be that much worse for performance, plus you can see objects structures with out neededing to enter any script 🤔

You also get the .changed event and its already replicated to the client so implementing UIs its easier

south nexus
#

it's a very common misconception started by people who can't handle other people who want to learn how to make games

errant crown
distant lanceBOT
#

studio** You are now Level 8! **studio

south nexus
#

it's sad

errant crown
south nexus
#

ironically if they had just set out to write their game instead of hyper-focusing on performance, they would already know how to do what they asked

#

that's why premature optimization is so bad, it stops you moving forward and learning new stuff

#

but y'know, to each their own 🤷

errant crown
severe merlin
#

@south nexus@errant crownum might need help once more 😭

#

my puzzle isnt puzzling

#

this is the updated puzzle, basically what its supposed to do is that once all tiles are in order it activates the proximity prompt of another part but is not doing that for some reason 💔

#

here is the full picture and completed, the tiles are in order from 1 to 25, 25 being the blank tile one

severe merlin
#

oh i just found out

#

but now idk how to like rotate it without breaking it

south nexus
errant crown
#

or you create a new cframe with newCframe = cframe:lookAt(same as before) and then loop trough all parts of the puzle and do part.cframe = newCframe:toWorldSpace(part.cframe)

#

vector_where_you_want_it_to_look_at this vector is the orientation you want the puzle to have

#

so if you want it to look towards the z direction, use vector3.zAxis