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

how do you fix "attempt to index nil with 'DevEnableMouseLock'"?

im trying to make shift lock not able to be turned on when player is seated because its binding over my code and i want shift lock to be able to be turned on when player is unseated

code

local Seats = {
	workspace["Model [2] Alpha Series of Class: Paired Dual Main Battery Station"].Seat,
	workspace["Model [2] Bravo Series of Main Battery Class "].Seat,
	workspace["Model [3] Charlie Series of Main Battery Class "].Seat
}
for i, Seat in pairs(Seats) do
	local RemoteEvents = game.ServerStorage["Begin[N]End"]
	local ReplicatedStorage = game:GetService("ReplicatedStorage")
	local ServerStorage = game:GetService("ServerStorage")
	local SeatProperty = Seat.Occupant
	
	Seat.Changed:Connect(function(Properties)
		local function OnSEAT(Player)
			if SeatProperty ~= nil then
				RemoteEvents.Parent = ReplicatedStorage
				Player.DevEnableMouseLock = false
				
			elseif Properties == "Occupant" and SeatProperty == nil then
				RemoteEvents.Parent = ServerStorage
				Player.DevEnableMouseLock = true
			end	
		end
		OnSEAT()
	end)
end

2 answers

You did not define a player with the OnSEAT() function. You just did OnSEAT() without any porperties.

local plr = game.Players.LocalPlayer
local Seats = {
    workspace["Model [2] Alpha Series of Class: Paired Dual Main Battery Station"].Seat,
    workspace["Model [2] Bravo Series of Main Battery Class "].Seat,
    workspace["Model [3] Charlie Series of Main Battery Class "].Seat
}
for i, Seat in pairs(Seats) do
    local RemoteEvents = game.ServerStorage["Begin[N]End"]
    local ReplicatedStorage = game:GetService("ReplicatedStorage")
    local ServerStorage = game:GetService("ServerStorage")
    local SeatProperty = Seat.Occupant

    Seat.Changed:Connect(function(Properties)
        local function OnSEAT(Player)
            if SeatProperty ~= nil then
                RemoteEvents.Parent = ReplicatedStorage
                Player.DevEnableMouseLock = false

            elseif Properties == "Occupant" and SeatProperty == nil then
                RemoteEvents.Parent = ServerStorage
                Player.DevEnableMouseLock = true
            end 
        end
        OnSEAT(plr)
    end)
end

I'm assuming it's in a LocalScript.

4 comments

0

Sorry! I meant parameters / arguments not properties.

0

ohhhh you were sooo wrong i used server script it was kinda my fault

0

dont worry i used PlayersService.PlayerAdded:Connect(function(Player) to solve the problem

0

i didnt want exploiters to start touching those remote event

problem fixed

--local Seats = 
--	{
--		workspace["Model [A]"].Seat,
--		workspace["Model [B]"].Seat,
--		workspace["Model [C]"].Seat,
--		workspace["Model [X]"].Seat,
--		workspace["Model [Y]"].Seat		
--	}

--local PlayersService = game:GetService("Players")

--PlayersService.PlayerAdded:Connect(function(Player)
--	for index, Seat in pairs(Seats) do
--		Seat.Changed:Connect(function(Property)
--			if Seat.Occupant ~= nil then
--				Player.DevEnableMouseLock = false
--			elseif Seat.Occupant == nil and Property == "Occupant" then
--				Player.DevEnableMouseLock = true	
--			end	
--		end)
--	end
--end)

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