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```
#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)
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 :)
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?
yes this should be server scipt
Ah
if you make local script everyone will create their own map
if you make everything anchored this not important
but if you dont anchor this will be awkward
Yea I mean I tried anchoring but the items still fall
li ke other players see another player can fly in sky
Literally everything basically
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
if you want to create everything when server is created
Yea
you dnt have to use player service
Ah I see
have you used server script
Before no, this is my first time using it
no i said because you should use server script now
Yes yes lol
ok
okay
But when running the script disappears (not sure if that is normal). The objects are still not anchored
yes this normal for server scripts
Oh okay, then that means our script is still wrong
Nope
Let me try that
Like having them in a fixed position right?
door.Position = Vector3(10,10,10)
something like this
door.Position = Vector3.new(10,10,10)
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?
are you trying to make a door selecting game?