How would I make a game be completed in any order?
I am working on a game were the main goal is to repair your space ship. How would I make it so the pieces can be rebuild in any order? there are 12 missing pieces
This is a bit of an abstract question, so here comes an abstract answer. Assuming you have a functions that can figure out if a specific part of the spaceship is found, like this:
local function isPart1Found()
-- determine if the player found part 1 of the spacship, then return...
end
Then the simplest answer is to use a long if-statement…
if isPart1Found() and isPart2Found() and ... then
-- Allow the player to continue, since they've found everything
end
But it’s probably a good idea to avoid a long condition like that. Instead, a for loop might be cleaner
local conditions = {isPart1Found, isPart2Found, isPart3Found, ... }
local function areAllPartsFound()
for _, func in pairs(conditions) do -- Iterate over conditions
if not func() then -- Check this condition
return false -- Didn't pass? Return false
end
end
return true -- All conditions passed
end
Okay ummm, im kinda confused I am a new dev, but I think this will work. here is a screenshot of the fill in script:
local Tool = game.Workspace.Findable.RWing
print("Hello")
-- list of account names allowed to go through the door.
permission = { "Right Wing" }
Door = script.Parent
function checkOkToLetIn(name)
for i = 1,#permission do
-- convert strings to all upper case, otherwise we will let in
-- "Telamon" but not "telamon" or "tELAMON"
if (string.upper(name) == string.upper(permission[i])) then return true end
end
return false
end
function onTouched(hit)
print("Door Hit")
local human = hit.Parent:findFirstChild("Humanoid")
if (human ~= nil ) then
-- a human has touched this door!
print("Human touched part")
-- test the human's name against the permission list
if (checkOkToLetIn(human.Parent.Name)) then
print("Human passed test")
Door.Transparency = 0
Door.CanCollide = true
wait()
game.Workspace.Number.Value = game.Workspace.Number.Value +1
script:Destroy()
Tool:Destroy()
end
end
end
connection = Door.Touched:connect(onTouched)
Edit: code formatting
The question is basically “how does your game record what the player has done?” because that will determine how you go about detecting what they’ve done.
Since you’re new, let me point you in the right direction. When you’re coding, your game might need to ask or answer some question a lot. In this case, you should delegate that to a ModuleScript (after all, if you changed the way your game records completion, you only want to change one thing).
So, perhaps you have a ModuleScript called “SpaceshipParts” in ServerScriptService. You can put functions inside a table, and return that table from the ModuleScript.
local SpaceshipParts = {}
-- This function's job is to record that a player found some ship part;
-- it is provided both the player and the part name.
function SpaceshipParts.recordFound(player, shipPartName)
-- In this example, I'll just create Folder in their player object.
local folder = Instance.new("Folder")
folder.Name = shipPartName .. "Found"
return folder
end
-- This function's job is to answer the question "has a player found part X?"
-- Like the other function, it is also given the player and shipPartName.
function SpaceshipParts.hasBeenFound(player, shipPartName)
-- Going off the Folder idea, all we have to do is call FindFirstChild
-- to figure out if recordFound has been called for this player/part name.
return player:FindFirstChild(shipPartName .. "Found") ~= nil
end
return SpaceshipParts
This is a very simple module that you could use in whatever finds the ship part, and whatever requires that it has been found. Here’s an example of a part that records a spaceship part was found:
local SpaceshipParts = require(game.ServerScriptService.SpaceshipParts)
local part = script.Parent
part.Touched:Connect(function (otherPart)
local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
if player then
SpaceshipParts.recordFound(player, "Fuselage") -- or whatever this part's name is
end
end)
Then, in your door that checks if they found the fuselage (and maybe all the other parts too), you can use SpaceshipParts.hasBeenFound
:
local SpaceshipParts = require(game.ServerScriptService.SpaceshipParts)
local part = script.Parent
part.Touched:Connect(function (otherPart)
local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
if player and SpaceshipParts.hasBeenFound(player, "Fuselage") then
-- Allow the player in (teleport, set door CanCollide = fasle, etc)
end
end)
It looks like you’re trying to repurpose some kind of door that allows only certain people in based on their name. While close, you probably want to write something from scratch rather than editing an existing piece of code. Use what you have as a guide, but don’t use it as a basis
Okay, so a couple of things, what is your RBX username, would you mind joining me in RBX Studio if not, Rewrite the script, add a module script.
Usernames on the devforum are the same as our Roblox usernames. Unfortunately I can’t hop into team create with you for this. There’s tutorials for everything I’ve mentioned, though, so be sure to ask more questions if you can’t find something.
okay, Thanks for helping me ill make sure to try what you said but im still really confused