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

when I run the script everything works for about three rounds in the game. will you help?

It gives me this error " ServerScriptService.Game:41: attempt to index nil with 'Name' " the line that isn't working is this line here 41 or 23 here : Status.Value = ChosenMap.Name.." Chosen"

-- Define Variables

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local ServerStorage = game:GetService("ServerStorage")

local MapsFolder = ServerStorage:WaitForChild("Maps")

local Status = ReplicatedStorage:WaitForChild("Status")

local GameLength = 15

local reward = 25

--Game Loop

while true do
	
	Status.Value = "Waiting for enough players"
	
	repeat wait(1) until game.Players.NumPlayers >= 1
	
	Status.Value = "Intermission"
	
	wait(15)
	
	local plrs = {}
	
	for i, player in pairs(game.Players:GetPlayers()) do
		if player then
			table.insert(plrs,player) -- Add each player into plrs table
		end
	end
	
	wait(5)
	
	local AvailableMaps = MapsFolder:GetChildren()
	
	local ChosenMap = AvailableMaps[math.random(1, 2)]
	
	Status.Value = ChosenMap.Name.." Chosen"
	
	local ClonedMap = ChosenMap
	ClonedMap.Parent = workspace

1 comment

0

You don't clone the Chosen Map, you must make a pointer to it. You then proceed to shift its location; this will eventually empty the 'MapsFolder'. P.S: 'NumPlayers' is deprecated, pair the length operator with a 'GetPlayers()" return. P.S.S: You should also use the length operator on 'AvailableMaps' to automatically provide the range: AvaliableMaps[math.random(1, #AvaliableMaps)]

1 answer

You didn't clone the chosen map. You are supposed to clone the chosen map so that it can be used next time for another round.

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