What do you want to achieve? Make a random map choosing script that has devproducts to choose the map and randomness.
What is the issue? Error: [09:05:57.233 - Workspace.map.main:80: attempt to index nil with ‘Name’]
What solutions have you tried so far? Pcalled it.
Script:
Module:
Also im trying to make it error to test if something changes the value of the name of the map in the playergui then it doesnt error but it uses random picking of the map.
local f = require(script.functions)
local wp = workspace
local runService = game:GetService("RunService")
local map = wp.map
local serverStorage = game:GetService("ServerStorage")
local replicatedStorage = game:GetService("ReplicatedStorage")
local mapStorage = serverStorage.maps
local players = game:GetService("Players")
local marketplaceService = game:GetService("MarketplaceService")
local mapQueue = {}
local productIds = {
chooseMap = 1008767645
}
local chosenMap
local mapTokens = wp.data.mapTokens
local playersLeft = wp.data.playersLeft.Value
local gameRunning = wp.data.gameRunning.Value
local gamesPlayedTotal = wp.data.gamesPlayedTotal.Value
players.PlayerAdded:Connect(function(plr)
local mapTokVal = Instance.new("IntValue",mapTokens)
mapTokVal.Name = plr.Name
end)
local function processReceipt(receiptInfo)
local plr = players:GetPlayerByUserId(receiptInfo.PlayerId)
if not plr then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
if plr then
if receiptInfo.ProductId == productIds.chooseMap then
local name = players:GetPlayerByUserId(receiptInfo.PlayerId).Name
local plr = players:GetPlayerByUserId(receiptInfo.PlayerId)
mapTokens:FindFirstChild(name).Value = mapTokens:FindFirstChild(name).Value + 1
replicatedStorage.remote.closeShopOpenChooseMap:FireClient(plr)
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
end
marketplaceService.ProcessReceipt = processReceipt
replicatedStorage.remote.selectMap.OnServerEvent:Connect(function(plr,map)
if mapTokens:FindFirstChild(plr.Name).Value > 0 then
mapTokens:FindFirstChild(plr.Name).Value = mapTokens:FindFirstChild(plr.Name).Value - 1
table.insert(mapQueue,map)
end
end)
local function setStatus(status)
replicatedStorage.remote.setStatus:FireAllClients(status)
end
while wait() do
mapTokens = wp.data.mapTokens
playersLeft = wp.data.playersLeft.Value
gameRunning = wp.data.gameRunning.Value
gamesPlayedTotal = wp.data.gamesPlayedTotal.Value
if gameRunning == false then
if gamesPlayedTotal > 0 then setStatus("Game ended!") end
wait(1)
setStatus("Choosing map...")
wait(1)
for i,v in pairs(map:GetChildren()) do
if v:IsA("Model") then
v:Destroy()
end
end
wait(0.5)
local builtMap,usedQueue = f.buildMap(map,mapStorage,mapQueue)
if usedQueue == true then
table.remove(mapQueue,1)
print("usedtable")
end
setStatus("The map "..builtMap.Name.." was chosen!")
wait(1)
end
end
Module:
local m = {}
function m.buildMap(map,maps,mapQueue)
if mapQueue[1] == nil then
local cCFrame = CFrame.new(0,0,0)
local modelList = maps:GetChildren()
local rand = Random.new()
local model = modelList[rand:NextInteger(1,#modelList)]
local modelClone = model:Clone()
modelClone:SetPrimaryPartCFrame(cCFrame)
modelClone.Parent = map
return modelClone,false
elseif mapQueue[1] ~= nil then
local pcallClone
local suc,err = pcall(function()
local cCframe = CFrame.new(0,0,0)
local modelFolder = maps
local model = modelFolder:FindFirstChild(mapQueue[1])
if model then
local modelClone = model:Clone()
modelClone.SetPromaryPartCFrame(cCframe)
modelClone.Parent = map
pcallClone = modelClone
end
end)
if not suc then
local cCFrame = CFrame.new(0,0,0)
local modelList = maps:GetChildren()
local rand = Random.new()
local model = modelList[rand:NextInteger(1,#modelList)]
local modelClone = model:Clone()
modelClone:SetPrimaryPartCFrame(cCFrame)
modelClone.Parent = map
return modelClone,true
elseif suc then
return pcallClone,true
end
end
end
return m