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
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.
huh? i dont get it
On like 6 you declare the variable "g" , on line 28 you do not pass any data so "g" is nil.
but how do i pass data on line 28 then?
call SetupSystem(DataToPass).