Local 'chosenmap' (a nil value)

So I wanted to make it where a serverscript sends a remotefunction to the local script and change the color of the text but the error I got was usual. I tried looking into it countless times, but I can’t fix the problem. The error said:

  12:55:49.118 - Players.Enchanted_Tix.PlayerGui.Core.Core:116: attempt to index local 'chosenmap' (a nil value)

server script: (A part of the script)

	local function maptext(chosenmap)
		local mapsettings = chosenmap.SettingsFolder
		text.Value = ""..mapsettings.MapName.Value.." ("..mapsettings.Difficulty.Value..") by: "..mapsettings.OwnerTitle.Value
		wait(1)
		for i, v in pairs(game.Players:GetPlayers()) do
			game.ReplicatedStorage.Functions.ColorTitle:FireAllClients(chosenmap, v)
		end
		wait(4)
		for i, v in pairs(game.Players:GetPlayers()) do
			game.ReplicatedStorage.Functions.WhiteTitle:FireAllClients(v)
		end
	end

local script: (A part of the script)

game.ReplicatedStorage.Functions.ColorTitle.OnClientEvent:Connect(function(chosenmap)
	script.Parent.TextList.Text.TextColor3 = (game.ReplicatedStorage.Difficulties:FindFirstChild(chosenmap.SettingsFolder.Difficulty.Value).Value)
end)

May you give us the line that fires the function?
You also made a mistake here:

it’s:

for i, v in pairs(game.Players:GetPlayers()) do
    game.ReplicatedStorage.Functions.ColorTitle:FireClient(v, chosenmap)
end

or:

game.ReplicatedStorage.Functions.ColorTitle:FireAllClients(chosenmap)

edit: i need the line that FIRED the function, you only showed us the function
Edit2: I fixed it, look above

1 Like

I showed you. It is in the server script.

1 Like

focus on this part:

It is the problem.

1 Like

Can you please try to print choosenmap above the for loop, inside the for loop and after the for loop? It might help you to find the issue

1 Like

Inside the local script it said ,“Nil” but inside the serverscript it said, “MapKit” (map).

1 Like

Is this the only error? Are you inserting a value when calling the function maptext? Is there something like

maptext(yourMap)

?

1 Like

That is the only error; there are values inside of the map. Yes, I did maptext(yourMap).

1 Like
local function maptext(chosenmap)
	local mapsettings = chosenmap.SettingsFolder
	text.Value = ""..mapsettings.MapName.Value.." ("..mapsettings.Difficulty.Value..") by: "..mapsettings.OwnerTitle.Value
	wait(1)
        print(chosenmap)
	for i, v in pairs(game.Players:GetPlayers()) do
                print(chosenmap)
		game.ReplicatedStorage.Functions.ColorTitle:FireAllClients(chosenmap, v)
                print(chosenmap)
	end
        print(chosenmap)
	wait(4)
	for i, v in pairs(game.Players:GetPlayers()) do
		game.ReplicatedStorage.Functions.WhiteTitle:FireAllClients(v)
	end
end

Can you please try this script and send me an image of the output please?

1 Like

Here:

aaa

1 Like

Can you explain to me why you are looping through all the players in rapid progression and sending that information to the LocalScript?

Hm ok when you try this script on the client:

game.ReplicatedStorage.Functions.ColorTitle.OnClientEvent:Connect(function(chosenmap,anotherValue)
        print(chosenmap,anotherValue)
	script.Parent.TextList.Text.TextColor3 = (game.ReplicatedStorage.Difficulties:FindFirstChild(chosenmap.SettingsFolder.Difficulty.Value).Value)
end)

What does he print then?

So everyone can receive the text color, and because I don’t have a local player option.

What is the type of MapKit? If it’s an instance, where is it stored? If it’s in a server-only location, LocalScripts obviously can’t access it, and roblox will, quite stupidly IMO, make the variable nil inside the LocalScript.

It is a model. It is a folder from serverstorage.

FireAllClients fires it to all the clients at once. If you want to fire variables to one client you need to use FireClient with the first variable being the target player.

Then LocalScripts cannot access it, and the variable will be nil. I’m not sure what you’re trying to accomplish here, so I don’t know what the purpose of MapKit is and where it should be stored. Problem found, next part is the solution to it.

So I added and changed the script in the Local Script. Tell me if it is right: (By the way, there is only 1 thing inside of the folder:

game.ReplicatedStorage.Functions.ColorTitle.OnClientEvent:Connect(function()
	local chosenmap = game.Workspace.MapFolder:GetChildren()
	script.Parent.TextList.Text.TextColor3 = (game.ReplicatedStorage.Difficulties:FindFirstChild(chosenmap.SettingsFolder.Difficulty.Value).Value)
end)

If there’s only 1 child inside the folder then reference only that one child directly and do not create a table of children because you do not need to. Also keep the chosenmap data in ReplicatedStorage so that the Server and Client can see it so you won’t keep getting nil.