Error, "attempt to index nil with gravity"

Making the serverside script, a module script for my map changing system (basically a serverscript tells this module below to teleport the player to the spawn location of the map and then tell the client to unload all maps and load the current map) and when I check the gravity value which is a num value stored in the map folder it says attempt to index nil with gravity, line 6.


local functions = {
	servermapload = function (player, area, spawnname, userespawnpoints, transition,transition_name, transition_description, transition_colour)
		local map = workspace.maps:WaitForChild(area)
		local gravity = workspace.maps..area.params.gravity.Value -- area is accepting a string and i dont think im concatenating it correctly
		local character = player.Character
		
		if userespawnpoints == true then
			print ("Using respawn points.")
			player:LoadCharacter()

		else
		local spawns = map.spawns
		local character = game.Players.MrGuyROBLOX.Character
		local pos = CFrame.new(spawns..spawnname.Value)
		local rot = CFrame.Angles(spawns..spawnname.rot.Value)
		character.HumanoidRootPart.CFrame =  pos * rot
		Players.LocalPlayer.Character.Parent = workspace
		end
		game.ReplicatedStorage.load_client_map:FireClient(area,transition,transition_name, transition_description, transition_colour)
		print("Fired client")
	end,
}

return functions

image

map loading test

print ("starting")

functions = require(game.ServerScriptService.server_functions);


	functions.servermapload(game.Players.MrGuyROBLOX,"test_map_1","1",false, false, "testmap1", "No description", Color3.new(0.0509804, 0.0509804, 0.0509804))
	print("loading map")```

I think your problem is right over here:

image

What if you change that to .maps[area] ? Because … is used to “add” strings and you want to locate a part in a service so you would have to use :FindFirstChild(variable) or [variable]

1 Like

Also with these:

image

You defined a variable and you’re adding an instance to a string so to fix it do spawns[spawnname.Value] or spawns:FindFirstChild(spawnname.Value)

(It’s like the same thing saying spawn…“Hello!”, it wouldn’t work but spawn[“Hello”] would work perfectly fine!

1 Like