Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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

Log in to vote
0
Answered by
yx10055 57
3 years ago

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.

0
Sorry! I meant parameters / arguments not properties. yx10055 57 — 3y
0
ohhhh you were sooo wrong i used server script it was kinda my fault proROBLOXkiller5 112 — 3y
0
dont worry i used PlayersService.PlayerAdded:Connect(function(Player) to solve the problem proROBLOXkiller5 112 — 3y
0
i didnt want exploiters to start touching those remote event proROBLOXkiller5 112 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

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)

Answer this question