Transferring Values { Server > Client }

Hi, I’ve recently started messing around with ModuleScripts and have ran into an issue -

I create Values in my MainModule script which are then transferred and adjusted throughout all of the ModuleScript’s in use; however, there is one part where the Values argument is sent through a RemoteEvent to the Client. Upon doing this, I’m unable to call any of the Values from my MainModule even to Read them as they come up as a ‘Nil’ value.

Can anyone recommend a work-around? Was hoping to edge away from physically creating new values in-game.

Below is the code used when the LocalScript requires the module:

   local System = { }

function System.FlightControl(Transfer, FlightUI)
  System = Transfer
  PilotSeat = System.Interior["PilotSeat"]
  CurrentPilot = game:GetService("Players").LocalPlayer
  local TiltY, TiltZ = System.Exterior:WaitForChild("Root").Orientation.Y, 0
  while PilotSeat.Occupant do wait()
    if System.Configuration.isWarping.Value == false then
      if PilotSeat.Throttle == -1 then
        System.BodyMovers["BodyVelocity"].Velocity
        = System.Exterior["Root"].CFrame.LookVector * -50/2
      elseif PilotSeat.Throttle == 0 then
        System.BodyMovers["BodyVelocity"].Velocity
        = System.Exterior["Root"].CFrame.LookVector * 0
      elseif PilotSeat.Throttle == 1 then
        System.BodyMovers["BodyVelocity"].Velocity
        = System.Exterior["Root"].CFrame.LookVector * 50
      end
      if PilotSeat.Steer == -1 then
        TiltY = TiltY + 1
        if TiltZ == 25 then
        else
          TiltZ = TiltZ + 1
        end
      elseif PilotSeat.Steer == 0 then
        if TiltZ == 0 then
        elseif TiltZ > 0 then TiltZ = TiltZ - 1
        elseif TiltZ < 0 then TiltZ = TiltZ + 1
        end
      elseif PilotSeat.Steer == 1 then
        TiltY = TiltY - 1
        if TiltZ == -25 then
        else
          TiltZ = TiltZ - 1
        end
        System.BodyMovers.BodyGyro.CFrame = CFrame.Angles(0, math.rad(TiltY), 0) * CFrame.Angles(0, 0, math.rad(TiltZ))
      end
    else
    end
  end
end
1 Like

I don’t have an answer but a tip for the future is to indent the code and not have spaces between every line. This would make it much easier for someone to read and understand your code.

1 Like

Unrelated, but please use intendations and calm with the whitespace. It makes your code much more readable and makes it easier for others to help.

1 Like

Here’s a formatted version:

local System = { }

function System.FlightControl(Transfer, FlightUI)
  System = Transfer
  PilotSeat = System.Interior["PilotSeat"]
  CurrentPilot = game:GetService("Players").LocalPlayer
  local TiltY, TiltZ = System.Exterior:WaitForChild("Root").Orientation.Y, 0
  while PilotSeat.Occupant do wait()
    if System.Configuration.isWarping.Value == false then
      if PilotSeat.Throttle == -1 then
        System.BodyMovers["BodyVelocity"].Velocity
        = System.Exterior["Root"].CFrame.LookVector * -50/2
      elseif PilotSeat.Throttle == 0 then
        System.BodyMovers["BodyVelocity"].Velocity
        = System.Exterior["Root"].CFrame.LookVector * 0
      elseif PilotSeat.Throttle == 1 then
        System.BodyMovers["BodyVelocity"].Velocity
        = System.Exterior["Root"].CFrame.LookVector * 50
      end
      if PilotSeat.Steer == -1 then
        TiltY = TiltY + 1
        if TiltZ == 25 then
        else
          TiltZ = TiltZ + 1
        end
      elseif PilotSeat.Steer == 0 then
        if TiltZ == 0 then
        elseif TiltZ > 0 then TiltZ = TiltZ - 1
        elseif TiltZ < 0 then TiltZ = TiltZ + 1
        end
      elseif PilotSeat.Steer == 1 then
        TiltY = TiltY - 1
        if TiltZ == -25 then
        else
          TiltZ = TiltZ - 1
        end
        System.BodyMovers.BodyGyro.CFrame = CFrame.Angles(0, math.rad(TiltY), 0) * CFrame.Angles(0, 0, math.rad(TiltZ))
      end
    else
    end
  end
end
2 Likes