Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help with a chooser script. [?]

Asked by 9 years ago

I have this function. but I need help with the table.remove() part. It keeps saying: 14:51:45.155 - Workspace.Script:8: bad argument #2 to 'remove' (number expected, got string)

local items = {"Innocent","Innocent","Sheriff","Murderer"}

function Choose()
for i = 1,#items do
local Player1 = items[math.random(#items)]
local Display = Instance.new("Hint",game.Workspace)
Display.Text = "You are: "..Player1
table.remove(items, Player1) --I need help removing whatever Player1 picks from items.
end
end

Choose()
1
Remember to tab your code.. Uroxus 350 — 9y

1 answer

Log in to vote
1
Answered by 9 years ago

Remember which one you picked

It's helpful sometimes just to take things one step at a time, particularly if you need to remember some important details.

local items = {"Innocent","Innocent","Sheriff","Murderer"}

function Choose()
    for i = 1,#items do
        local n = math.random(#items)
        local Player1 = items[n]
        local Display = Instance.new("Hint",game.Workspace)
        Display.Text = "You are: "..Player1
        table.remove(items, n) -- Remove the chosen entry.
    end
end

Choose()

I don't think your code will work how you want it to, despite the change I've made. That's your issue.

Ad

Answer this question