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

I am making a game like piggy called "Green Head" but what is this error?

My error is this: ServerScriptService.Game Logic.RoundModule:24: attempt to get length of a nil value Here my script :

local module = {}

local status = game.ReplicatedStorage:WaitForChild("Status")

function module.Intermission(length)
	for i = length,0,-1 do
		status.Value = "Nex round starts in "..i.." seconds"
		wait(1)
	end
end

function module.SelectChapter()
	local rand = Random.new()
	local chapters = game.ReplicatedStorage.Chapters:GetChildren()
	local chosenChapter = chapters[rand:NextInteger(1,#chapters)]
	
	return chosenChapter
end

function module.ChooseGreenBall(players)
	
	local RandomObj = Random.new()
	
	local chosenGreenBall = players[RandomObj:NextInteger(1,#players)]
	
	return chosenGreenBall
	
end

function module.DressGreenBall(greenball)
	local character = game.ServerStorage.GreenHead:Clone()
	character.Name = greenball.Name
	
	greenball.Character = character
	character.Parent = workspace
end

return module

3 comments

0

Also the script is broken i am new here

0

Please format all of the script in lua formatting.

0

There is not enough information to solve this problem since the script calling the function is not defined. Your function is perfectly fine, but the parameter, players is not.

1 answer

You can use math.random Instead of Random.new

function module.ChooseGreenBall(players)

    local MathRandom = math.random()

    local chosenGreenBall = players[MathRandom(1,#players)]

    return chosenGreenBall

end

1 comment

0

I made a mistake, local MathRandom = math.random() must be local MathRandom = math.random

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