Ad
Log in to vote
0

"Players.squidiskool.Backpack.RCRemote.Receiver:20: attempt to index nil with 'Name' "?

Asked by 7 days ago
Edited 7 days ago

I have a tool that is supposed to connect to an rc car, and lets you drive it. It connects, but it doesn't drive. I made it print when it fires, it fires, and I made it print when it receives the RemoteEvents. They both print. Why isn't the car driving? It's not the car itself, as it controls with a previous controller. The serverscript is parented to the tool, and the localscript is parented to the tool as well. "VehConnected" is an ObjectValue inside the tool. It's the vehicle. "DriveSignals" is a folder holding the RemoteEvents inside the tool. Also when the tool is unequipped and equipped, the error "Players.squidiskool.Backpack.RCRemote.Receiver:20: attempt to index nil with 'Name' " is spammed and the lag is super high. Can anybody fix that too? The error occurs on MANY different lines. LocalScript:

local UIS = game:GetService("UserInputService")
local equipped = false
local tool = script.Parent
script.Parent.Equipped:Connect(function()
    equipped = true
end)
script.Parent.Unequipped:Connect(function()
    equipped = false
end)

while wait() do
    if tool.VehConnected.Value ~= nil then
        UIS.InputBegan:Connect(function(THROTTLE)
            if THROTTLE.KeyCode == Enum.KeyCode.W and equipped then
                tool.DriveSignals.Throttle:FireServer()
            end
        end)
        UIS.InputEnded:Connect(function(BRAKES)
            if BRAKES.KeyCode == Enum.KeyCode.W or Enum.KeyCode.S and equipped then
                tool.DriveSignals.Brakes:FireServer()
            end
        end)

        UIS.InputBegan:Connect(function(LEFT)
            if LEFT.KeyCode == Enum.KeyCode.A and equipped then
                tool.DriveSignals.Left:FireServer()
            end
        end)
        UIS.InputEnded:Connect(function(STRAIGHT)
            if STRAIGHT.KeyCode == Enum.KeyCode.A or Enum.KeyCode.D and equipped then
                tool.DriveSignals.Straight:FireServer()
            end
        end)

        UIS.InputBegan:Connect(function(RIGHT)
            if RIGHT.KeyCode == Enum.KeyCode.D and equipped then
                tool.DriveSignals.Right:FireServer()
            end
        end)
    end
end

ServerScript:

local tool = script.Parent
local drivesignals = tool:WaitForChild("DriveSignals")
local vehconnected = tool:WaitForChild("VehConnected")
local left = drivesignals:WaitForChild("Left")
local straight = drivesignals:WaitForChild("Straight")
local right = drivesignals:WaitForChild("Right")
local throttle = drivesignals:WaitForChild("Throttle")
local reverse = drivesignals:WaitForChild("Reverse")
local brakes = drivesignals:WaitForChild("Brakes")
left.OnServerEvent:Connect(function()
        if vehconnected.Value.Name == "KenBlockFiesta" then
            vehconnected.Value.chassis.FL.Orientation = Vector3.new(0, -165, 0)
            vehconnected.Value.chassis.FR.Orientation = Vector3.new(0, 15, 0)
        else
            vehconnected.Value.FLWHEELMOUNT.HingeConstraint.TargetAngle = -15
            vehconnected.Value.FRWHEELMOUNT.HingeConstraint.TargetAngle = -15
        end
end)
straight.OnServerEvent:Connect(function()
        if vehconnected.Value.Name == "KenBlockFiesta" then
            vehconnected.Value.chassis.FL.Orientation = Vector3.new(0, 180, 0)
            vehconnected.Value.chassis.FR.Orientation = Vector3.new(0, 0, 0)
        else
            vehconnected.Value.FLWHEELMOUNT.HingeConstraint.TargetAngle = -0
            vehconnected.Value.FRWHEELMOUNT.HingeConstraint.TargetAngle = -0
        end
end)
right.OnServerEvent:Connect(function()
    if vehconnected.Value.Name == "KenBlockFiesta" then
        vehconnected.Value.chassis.FL.Orientation = Vector3.new(0, 165, 0)
        vehconnected.Value.chassis.FR.Orientation = Vector3.new(0, -15, 0)
    else
        vehconnected.Value.FLWHEELMOUNT.HingeConstraint.TargetAngle = 15
        vehconnected.Value.FRWHEELMOUNT.HingeConstraint.TargetAngle = 15
    end
end)
throttle.OnServerEvent:Connect(function()
        if vehconnected.Value.Name == "KenBlockFiesta" then
            vehconnected.Value.RL.HingeConstraint.AngularVelocity = 500
            vehconnected.Value.RR.HingeConstraint.AngularVelocity = -500
        else
            local maxspeed = vehconnected.Value.MaxSpeed
            vehconnected.Value.FLWHEELMOUNT.CylFL.AngularVelocity = maxspeed.Value
            vehconnected.Value.FRWHEELMOUNT.CylFR.AngularVelocity  = -maxspeed.Value
            vehconnected.Value.RLWHEELMOUNT.CylRL.AngularVelocity = maxspeed.Value
            vehconnected.Value.RRWHEELMOUNT.CylRR.AngularVelocity  = -maxspeed.Value
        end
end)
reverse.OnServerEvent:Connect(function()
        if vehconnected.Value.Name == "KenBlockFiesta" then
            vehconnected.Value.RL.HingeConstraint.AngularVelocity = -500
            vehconnected.Value.RR.HingeConstraint.AngularVelocity = 500
        else
            local maxspeed = vehconnected.Value.MaxSpeed
            vehconnected.Value.FLWHEELMOUNT.CylFL.AngularVelocity = -maxspeed.Value
            vehconnected.Value.FRWHEELMOUNT.CylFR.AngularVelocity  = maxspeed.Value
            vehconnected.Value.RLWHEELMOUNT.CylRL.AngularVelocity = -maxspeed.Value
            vehconnected.Value.RRWHEELMOUNT.CylRR.AngularVelocity  = maxspeed.Value
        end
end)
brakes.OnServerEvent:Connect(function()
        if vehconnected.Value.Name == "KenBlockFiesta" then
            vehconnected.Value.RL.HingeConstraint.AngularVelocity = 0
            vehconnected.Value.RR.HingeConstraint.AngularVelocity = 0
        else
            vehconnected.Value.FLWHEELMOUNT.CylFL.AngularVelocity = 0
            vehconnected.Value.FRWHEELMOUNT.CylFR.AngularVelocity  = 0
            vehconnected.Value.RLWHEELMOUNT.CylRL.AngularVelocity = 0
            vehconnected.Value.RRWHEELMOUNT.CylRR.AngularVelocity  = 0
        end
end)

There's also a serverscript that removes the vehicle references when it's unequipped. This is parented to the tool.

local value = script.Parent.VehConnected
local tool = script.Parent

tool.Unequipped:Connect(function()
    if value.Value ~= nil then
        print("Remote unequipped with vehicle connected, disconnecting...")
        value.Value.RemoteControlConnected.Value = false
        wait(3)
        value.Value = nil
    end
end)

Here's the model of the broken remote since god forbid I'm not inserting all the scripts. (Also ignore the errors on the car itself) https://roblox.com/library/6432163817/broken

0
The answer is really simple: There is no assigned value to VehConnected. Lua errors are straightforward, and I don't know how you're not getting it. DeceptiveCaster 3513 — 6d
0
I know why that's happening. But why are the remotes still firing? squidiskool 200 — 6d
0
Hello?? squidiskool 200 — 6d
0
Sooo... squidiskool 200 — 6d
View all comments (2 more)
0
Like Deceptive said, there is no value assigned to VehConnected. Assign a value and then try. JailBreaker_13 352 — 6d
0
But I don't want the remote to be connected to anything when it's unequipped????? squidiskool 200 — 5d

2 answers

Log in to vote
0
Answered by 6 days ago

vehconnected is nil, which means it doesn't exist.

0
Even when I put equipped in the receiver, the error still pops up. Why isn't the Tool listening to the "equipped" variable? squidiskool 200 — 6d
Ad
Log in to vote
0
Answered by 5 days ago

This way of moving the vehicle was bad to begin with. Instead, I just used a vehicleseat.

Answer this question