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

bad argument 2# to random,(interval is empty)?

it seems like the 30 line has an math random error, but i don't see anything wrong with it . i don't know what the output is trying to tell me, but here is the script i made:

players = {}
local chosenplayer1 = nil
local chosenplayer2 = nil
local stringvalue = game.Workspace.Baseplate.event.Value
local serverstore = game:GetService("ServerStorage")
events = {"test"}
local chosenevent = nil


local function onCharacterAdded(chr)
	table.insert(players, chr)
end

local index = -1

local function OnCharacterRemoved(removed)
	for i, v in pairs(players) do
		if removed == v then
			index = i
		end
	end
	table.remove(players, index)
end

local function ChooseEvent()
	local chooseevent = events[math.random(1,#events)]
	chosenevent = chooseevent
	print(chosenevent)
	if chosenevent == "test" then
		local value = players[math.random(1,#players)]
		  stringvalue = value
			local char = game.Workspace:FindFirstChild(stringvalue)
				print(char)
	end
end


game.Players.PlayerAdded:Connect(onCharacterAdded)
game.Players.PlayerRemoving:Connect(OnCharacterRemoved)
ChooseEvent()

1 comment

0

very confusing to me, lolz

1 answer

✓ Accepted answer

#events represents a number less than or equal to the first value in the math.random's parameters (1), increase the number of values in the table events to fix it.

See math for more info

1 comment

0

Great! Short but useful, keep up the good work! Upvoted.

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