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

Why does it say that its a nil value?

I got a problem that i dont know how to fix, It is so im trying to know if a player sits in the seat and ya like that if not. I want it to shoot when i only sit in the seat. Before i didint have this script then it worked to shot even when i wasent in the seat but now when i got this script that will do so you only can shoot when u are in the seat. Then it dosent work why?

local sitDetector = require(game.ServerScriptService.SitDetector)
local BasicName = "Basic"

local boxes = {}

function SetupSystem(g)
	
	g.ChildRemoved:connect(function(b)
		if (b:IsA("Model") and b.Name == BasicName and boxes[b]) then
			boxes[b] = nil
		end
	end)
	
	local function CreateSitDetector(Basic)
		local detector = sitDetector:Create(Basic.Seat)
		detector.PlayerSit:connect(function(plr)
			game.ReplicatedStorage.ClientRequest.GiveControl:InvokeClient(plr, Basic)
		end)
		detector.PlayerStand:connect(function(plr)
			game.ReplicatedStorage.ClientRequest.RemoveControl:InvokeClient(plr, Basic)
		end)
	end
	
	CreateSitDetector(g[BasicName])
	
end

SetupSystem()

Error:

17:41:47.433 - ServerScriptService.BoxHandler:8: attempt to index local 'g' (a nil value)
17:41:47.434 - Stack Begin
17:41:47.434 - Script 'ServerScriptService.BoxHandler', Line 8 - global SetupSystem
17:41:47.434 - Script 'ServerScriptService.BoxHandler', Line 28
17:41:47.434 - Stack End

And if i dont have that ChildAdded on line 8 then i get the same error on line 24 why?

5 comments

0

When you run the function on line 28 you do not pass a parameter so "g" is nil giving you the error on line 8.

0

huh? i dont get it

0

On like 6 you declare the variable "g" , on line 28 you do not pass any data so "g" is nil.

0

but how do i pass data on line 28 then?

0

call SetupSystem(DataToPass).

1 answer

✓ Accepted answer

Why does it say that its a nil value?

Because you are not passing a value in line 28.

You declare in your SetupSystem function that you want value g, What is 'g'?

Put line 28 as SetupSystem(DataToPass) so that g is not nil.

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