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

Keep Getting an Error (Userdata value) but script is correct..?

Asked by
Kblow1 53
6 years ago

I have it set-up in ReplicatedStorage with a folder called "game" and 2 parts inside. Inside of the workspace i have a part called "Base" and inside of it is a ClickDetector and this script. Why doesnt it work? Please help

local replicatedStorage = game:GetService("ReplicatedStorage")
local gamez = replicatedStorage:WaitForChild("game")

function Clicked()
    local pl = gamez:GetChildren()
    local selectedIndex = math.random(1,#gamez)
    local gmae = pl[selectedIndex]:Clone()
    gmae.Parent = game.Workspace
    gmae.Name = "Choosen"
    return pl[selectedIndex].Name
end
script.Parent.ClickDetector.MouseClick:connect(Clicked)

Here is the error

Workspace.Base.Script:6: attempt to get length of upvalue 'gamez' (a userdata value)

1 answer

Log in to vote
0
Answered by 6 years ago

I believe your error was on line 6. Here's the fix.

local replicatedStorage = game:GetService("ReplicatedStorage")
local gamez = replicatedStorage:WaitForChild("game")

function Clicked()
    local pl = gamez:GetChildren()
    local selectedIndex = math.random(1,#pl) -- You tried to get the 'gamez' from line 2
    local gmae = pl[selectedIndex]:Clone()
    gmae.Parent = game.Workspace
    gmae.Name = "Choosen"
    return pl[selectedIndex].Name
end
script.Parent.ClickDetector.MouseClick:connect(Clicked)

Ad

Answer this question