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

Hello im in need of a little help with doing a random selection?

Hello everyone im zamabikillerz101 (Beginner scripter)

I am trying to make a rust based game in roblox (I know its been done) however just for fun, i have gotten 1 node to spawn in random locations, however when i have added 2 other types of nodes into the folder and make the script pick a random node and clone it it doesnt work. can anyone help? keeps returning // 02:14:22.684 - ServerScriptService.Script:10: attempt to index local 'nodes' (a number value) //

My current CODE



--Script for spawning random nodes around the map in random positions :)
--Variables--
local nodeamount = 0 --Set starting amount
local node = game.ReplicatedStorage.Nodes:GetChildren() --Finds the node
local nodes = math.random(1, #node)

while nodeamount < 5 do -- if nodeamount is less than 5 continue the script // if =5 stop script
	local nodes = math.random(1, #node)
	local cloned =  nodes:Clone() --Clone the node
	cloned.Name = ("NodeID:" .. math.random(1000))--Assigns a random ID number to the spawned Node 
	cloned.Position = Vector3.new(math.random(-100,100),1,math.random(-100,100)) --Find a location to spawn the node
	cloned.Parent = game.Workspace -- When found location Parent it to the map
	cloned.Anchored = true --Stops the node from being moved around 
	nodeamount = nodeamount + 1 --Increase the int +1 each time until reaches 1 
	print ("Nodes Currently on the map:" .. nodeamount) -- Prints a message in console
	wait(0.5)-- Waits .5 seconds before re reading the script.
end -- End

1 answer

If you change line 9 to this it should work:

local cloned =  node[nodes]:Clone()

4 comments

0

Addition > This will work since you are cloning a random number instead of the object.

0

Hello Thank you for the answer

0

However it only spawns 1 type of node instead of the 5 diffrent type of nodes

0

The code seems correct. Are there definitely 5 different types of nodes in game.ReplicatedStorage.Nodes?

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