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

getting random child from model gives error?

When I try to get a random tool aka child i get an error Players.Danglt.Backpack.Remote.Tool:14: attempt to index field 'random' (a function value)

local crate2 = storage.Crate:Clone()
	for i,v in pairs(storage.rewards:GetChildren()) do
		local reword = v[math.random[1]]:Clone()
		reword.Parent = crate2.Reward
	crate2.Parent = workspace
	crate2.Configurations.Owner.Value = plr.Name
	for i = 1,1 do -- Replace 100 with an increment of times
crate2.Base:SetPrimaryPartCFrame(char.Torso.CFrame + Vector3.new(10,10,0))
end

2 comments

0

I am bad at this, but maybe try a # before the 1 in line 3...??

0

nope, now i get Players.Danglt.Backpack.Remote.Tool:14: attempt to get length of a number value

1 answer

[] is for index,

() is for function,

so it should be, math.random(1)

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