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

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

Asked by 4 years ago
Edited 4 years ago

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

0
Also the script is broken i am new here Clxud_D 9 — 4y
0
Please format all of the script in lua formatting. youtubemasterWOW 2741 — 4y
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. Sir_Ragealot 72 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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
0
I made a mistake, local MathRandom = math.random() must be local MathRandom = math.random OverAttribute 20 — 4y
Ad

Answer this question