#So I'm not sure why but when I run the game to test it, the objects are not anchored. Any idea why?

59 messages · Page 1 of 1 (latest)

sharp onyx
#
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

local currentRoom = 1
local doorCount = 1

function createRoom(doorCount)
    local room = Instance.new("Part")
    room.Name = "Room"
    room.Size = Vector3.new(100, 100, 100)
    room.Anchored = true
    room.Parent = game.Workspace

    local doors = {}
    for i = 1, doorCount do
        local door = Instance.new("Part")
        door.Name = "Door"
        door.Size = Vector3.new(10, 10, 10)
        door.Anchored = true
        door.Parent = room

        local clickDetector = Instance.new("ClickDetector")
        clickDetector.Parent = door

        table.insert(doors, door)
    end

    local correctDoor = doors[math.random(1, doorCount)]
    correctDoor.Name = "CorrectDoor"

    return room, correctDoor
end

function onDoorClicked(door)
    if door.Name == "CorrectDoor" then
        currentRoom = currentRoom + 1
        doorCount = doorCount * 2
        character.Parent = createRoom(doorCount).Parent
    else
        character:Kill()
        wait(1)
        character.Parent = player.Character
    end
end

character.Parent = createRoom(doorCount).Parent

while true do
    for _, door in pairs(character.Parent:GetChildren()) do
        if door:IsA("Part") and door.Name == "Door" then
            door.ClickDetector.MouseClick:Connect(function()
                onDoorClicked(door)
            end)
        end
    end

    wait(0.1)
end```
brave dew
sharp onyx
# brave dew try changeing parent before anchoring

Didn't work, but I'm guessing it's me not doing right

local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

local currentRoom = 1
local doorCount = 1

function createRoom(doorCount)
  local room = Instance.new("Part")
  room.Name = "Room"
  room.Size = Vector3.new(100, 100, 100)
  room.Parent = game.Workspace
  room.Anchored = true

  local doors = {}
  for i = 1, doorCount do
    local door = Instance.new("Part")
    door.Name = "Door"
    door.Size = Vector3.new(10, 10, 10)
    door.Parent = room
    door.Anchored = true

    local clickDetector = Instance.new("ClickDetector")
    clickDetector.Parent = door

    table.insert(doors, door)
  end

  local correctDoor = doors[math.random(1, doorCount)]
  correctDoor.Name = "CorrectDoor"

  return room, correctDoor
end

function onDoorClicked(door)
  if door.Name == "CorrectDoor" then
    currentRoom = currentRoom + 1
    doorCount = doorCount * 2
    character.Parent = createRoom(doorCount).Parent
  else
    character:Kill()
    wait(1)
    character.Parent = player.Character
  end
end

character.Parent = createRoom(doorCount).Parent

while true do
  for _, door in pairs(character.Parent:GetChildren()) do
    if door:IsA("Part") and door.Name == "Door" then
      door.ClickDetector.MouseClick:Connect(function()
        onDoorClicked(door)
      end)
    end
  end

  wait(0.1)
end
#

Could you just tell me what is wrong and what to do? I want to do it myself

#

Will appreciate that as I'm trying to get used to coding :)

sharp onyx
# brave dew this a server script right?

I mean I guess so? So what I am trying to do is I have not built anything within the game. It's blank. And so I'm basically creating the whole game itself with scripting which includes building. Nothing too fancy for now but yeah. So when members join (Or at least first player joins) the map would be created. Would that be a server script?

sharp onyx
#

Ah

brave dew
#

if you make local script everyone will create their own map

sharp onyx
#

Hmm

#

No what I am trying to do is basically creating one map per server

brave dew
#

if you make everything anchored this not important

#

but if you dont anchor this will be awkward

sharp onyx
#

Yea I mean I tried anchoring but the items still fall

brave dew
#

li ke other players see another player can fly in sky

sharp onyx
#

Literally everything basically

brave dew
#

firstly

#

try making it on server script

sharp onyx
#

How would I do that?

#

Don't mind me I'm not really a coder and this is an experimental learning through machine learning

#

so I may ask questions in details which I hope you won't mind

#

I added my recent script in StarterPlayerScripts

brave dew
#

create a script

#

in server script service

#

maybe named main

sharp onyx
#

Ooh I see

#

I moved my script there instead

brave dew
#

if you want to create everything when server is created

sharp onyx
#

Yea

brave dew
#

you dnt have to use player service

sharp onyx
#

Ah I see

brave dew
sharp onyx
brave dew
#

no i said because you should use server script now

sharp onyx
#

Yes yes lol

brave dew
#

ok

sharp onyx
brave dew
#

okay

sharp onyx
#

But when running the script disappears (not sure if that is normal). The objects are still not anchored

brave dew
sharp onyx
#

Oh okay, then that means our script is still wrong

brave dew
#

have you set positions of parts?

#

in this script

sharp onyx
#

Let me try that

#

Like having them in a fixed position right?

brave dew
#

door.Position = Vector3(10,10,10)

#

something like this

#

door.Position = Vector3.new(10,10,10)

#

this*

sharp onyx
# brave dew this*
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

local currentRoom = 1
local doorCount = 1

function createRoom(doorCount, position)
  local room = Instance.new("Part")
  room.Name = "Room"
  room.Size = Vector3.new(100, 100, 100)
  room.Position = position
  room.Anchored = true
  room.Parent = game.Workspace

  local doors = {}
  for i = 1, doorCount do
    local door = Instance.new("Part")
    door.Name = "Door"
    door.Size = Vector3.new(10, 10, 10)
    door.Anchored = true
    door.Parent = room

    local clickDetector = Instance.new("ClickDetector")
    clickDetector.Parent = door

    table.insert(doors, door)
  end

  local correctDoor = doors[math.random(1, doorCount)]
  correctDoor.Name = "CorrectDoor"

  return room, correctDoor
end

function onDoorClicked(door)
  if door.Name == "CorrectDoor" then
    currentRoom = currentRoom + 1
    doorCount = doorCount * 2
    local newRoom, newDoor = createRoom(doorCount, door.Position + Vector3.new(100, 0, 0))
    character.Parent = newRoom
  else
    character:Kill()
    wait(1)
    character.Parent = player.Character
  end
end

local firstRoom, firstDoor = createRoom(doorCount, Vector3.new(0, 0, 0))
character.Parent = firstRoom

while true do
  for _, door in pairs(character.Parent:GetChildren()) do
    if door:IsA("Part") and door.Name == "Door" then
      door.ClickDetector.MouseClick:Connect(function()
        onDoorClicked(door)
      end)
    end
  end

  wait(0.1)
end
#

The positioning is a bit below

#

That code is not working as well, however is it because I should position the objects before they are created in the world?

brave dew
#

i tried the script and it worked

#

the parts is anchored

sharp onyx
#

Why isn't it working for me

brave dew
#

are you trying to make a door selecting game?