Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I prevent this script from choosing the same floor twice?

How can I prevent this script from choosing the same floor twice?

function ChooseFloor()
	local Floors = game.ReplicatedStorage.Floors:GetChildren()
	local PickFloor = math.random(1, #Floors)
	local SelectedFloor = Floors[PickFloor]:Clone()
	SelectedFloor.Name = "Floor"
	SelectedFloor.Parent = game.Workspace
end

1 answer

✓ Accepted answer
function ChooseFloor()
    local Floors = game.ReplicatedStorage.Floors:GetChildren()
    local PickFloor = math.random(1, #Floors)
    if not string.find(PickFloor.Name,"done") then
    local SelectedFloor = Floors[PickFloor]:Clone()
    PickFloor.Name = PickFloor.Name.."done"
    SelectedFloor.Name = "Floor"
    SelectedFloor.Parent = game.Workspace
end
end

What this does is it adds "done" to any already used floor and checks if it has already be done at the begin.

8 comments

0

I get this error: ServerScriptService.ElevatorScript:85: attempt to index local 'PickFloor' (a number value)

0

Can you post the whole script so I can see in what line the script errors?

0

It's line 4

0

Change string.find to string.match

0

k

0

Doesn't work still (same error)

0

I would suggest to put a boolean value into each floor and change it to true at the end of the function and check if it is true at the begin of the function.

0

Could you script that into an answer? I'm not sure how to..

This discussion is preserved as it was. New answers, comments, and votes are closed.