Hell0! I was just moving around some free models and i wanted to test a car and after it worked in a test world, i wanted to place it to my world but the same car ended up with this error and only the part effected is lines given so the car wont move. The code is over 300 lines so i will give the code if no solution can be found by some guessing
Can you send a screenshot of line 26 and any relevant variables?
local function initializeVehicle(vehicle, functional, seats, wheels, lights)
functional.Mass.Alarm.SoundId = "rbxassetid://"..vehicle:GetAttribute("Car_AlarmID");
functional.Mass.Horn.SoundId = "rbxassetid://"..vehicle:GetAttribute("Car_HornID");
functional.Mass.Radio.SoundId = "rbxassetid://"..vehicle:GetAttribute("Car_RadioID");
local density = vehicle:GetAttribute("Car_Mass") / (functional.Mass.Size.X * functional.Mass.Size.Y * functional.Mass.Size.Z);
functional.Mass.CustomPhysicalProperties = PhysicalProperties.new(density, 0, 0, 0, 0);
seats.VehicleSeat.MaxSpeed = vehicle:GetAttribute("Speed_MaxForward");
for each, wheel in pairs(wheels:GetChildren()) do
if wheel.CylindricalConstraint.AngularActuatorType == Enum.ActuatorType.Motor then
wheel.CylindricalConstraint.MotorMaxTorque = vehicle:GetAttribute("Car_Torque");
wheel.CylindricalConstraint.MotorMaxAngularAcceleration = vehicle:GetAttribute("Car_Acceleration");
end
if wheel:FindFirstChild("SpringConstraint") then
if vehicle:GetAttribute("Suspension_Automatic") then
local adjustedMass = vehicle:GetAttribute("Car_Mass") * 1
local stiffness = (adjustedMass * workspace.Gravity) / vehicle:GetAttribute("Suspension_Height") / #wheels:GetChildren();
local damping = (2 * math.sqrt(adjustedMass * stiffness) * vehicle:GetAttribute("Suspension_Tuning")) / #wheels:GetChildren();
vehicle:SetAttribute("Suspension_Stiffness", stiffness);
vehicle:SetAttribute("Suspension_Damping", damping);
end
wheel.SpringConstraint.Damping = vehicle:GetAttribute("Suspension_Damping");
wheel.SpringConstraint.Stiffness = vehicle:GetAttribute("Suspension_Stiffness");
wheel.SpringConstraint.FreeLength = vehicle:GetAttribute("Suspension_Height");
end
end
for each, light in pairs(lights:GetChildren()) do
if light.Name == "Head" then
light.Color = vehicle:GetAttribute("Light_HeadOff");
elseif light.Name == "Tail" then
light.Color = vehicle:GetAttribute("Light_TailOff");
elseif light.Name == "Reverse" then
light.Color = vehicle:GetAttribute("Light_ReverseOff");
elseif light.Name == "LeftIndicator" or light.Name == "RightIndicator" then
light.Color = vehicle:GetAttribute("Light_IndicatorOff");
elseif light.Name == "Strobe1" then
light.Color = vehicle:GetAttribute("Light_StrobeOff");
light.PointLight.Color = vehicle:GetAttribute("Light_Strobe1On");
elseif light.Name == "Strobe2" then
light.Color = vehicle:GetAttribute("Light_StrobeOff");
light.PointLight.Color = vehicle:GetAttribute("Light_Strobe2On");
end
end
end
local Players = game:GetService("Players");
local vehicles = workspace:WaitForChild("Vehicles");
local remoteCooldowns = {};
it was part of a function so i guessed it was better this way. also it had the same error in the other world but it worked normal unlike my other world
From the code you have provided line 26 is :
wheel.SpringConstraint.Stiffness = vehicle:GetAttribute("Suspension_Stiffness");
Are you sure that the car has an Attribute named “Suspension_Stiffness” and that it is a number/numerical attribute?
Something like this I mean
Oh im really sorry for the misunderstanding, the actual line 26 is
wheel.CylindricalConstraint.MotorMaxAngularAcceleration = vehicle:GetAttribute("Car_Acceleration");
Also speaking of arttributes, i tried adding a number arttribute named Car_Acceleration and now its printing no errors but doesnt work as intended aswell. (P.S. i checked the working one and no Car_Acceleration is in arttributes aswell. Im mind boggled right now)
Hmm… since you mentioned it’s a free model could you possibly send the link to the model so I can check the scripts?
Since you checked the working model, maybe the attribute is set from the script.
Could you also add a print
statement at line 25:
print(vehicle:GetAttribute("Car_Acceleration"))
This way, we can see what the attribute returns.
Alright. Well its a semi-free model. It is from another developer and the developer seems offline so i wanted help from people in the forum but here is the world. You will get the meaning of the code i guess
Vehicle-Testing.rbxl (376.0 KB)
Now i will try your idea
Hmm… Alright I think I found the issue!
While the script seems alright, you don’t have a script to change the Car_Running
attribute!
To fix the first issue (value of type nil cannot be converted to a number), just add a number attribute to each vehicle.
OLD
To fix the second issue (The car is not moving), create a simple local script inside StarterPlayerScripts.
e.g.
local vehicles = workspace:WaitForChild("Vehicles")
local userInputService = game:GetService("UserInputService")
for _, vehicle in pairs(vehicles:GetChildren()) do
userInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.W then
vehicle:SetAttribute("Car_Running", true)
elseif input.KeyCode == Enum.KeyCode.S then
vehicle:SetAttribute("Car_Running", false)
end
end)
end
So now, the Attribute actually changes.
Edit:
I found a script named CarLocalCore
within StarterCharacterScripts
. When you press T
, the engine starts, enabling the car to move.
Hope this helped you, if you have any other questions let me know!
Well I have not so good news
I had the CarLocalCore
placed entire time and the first solution didnt work
oops
Does it print any errors again? Because I tried it out and it works…
Have you placed the attribue correctly?
Click the vehicle (for example Toyota Camry LE)
Go to properties and you’ll see the Attributes page. Click the plus (+) button:
A window will pop up; enter the name and type as follows, then press Save:
Then you’ll see the new attribute
Well i guess i can show you like this the fastest way. Watch issue | Streamable
If it works in another rbxl file than the original, can you send it to me?
notworking.rbxl (219.5 KB)
well can you try to use this? I picked only things i needed and now its not working
I honestly don’t know. For the past 2 hours, I’ve been trying to find the issue, but I cannot. While it works on the game you originally sent me, it doesn’t work when I try to copy the scripts to a new game. Maybe it has something to do with the environment and the physics side of Roblox since you use velocity, etc., to measure speed. If the game you sent me was originally created by the developer you mentioned previously, ask him if he has changed something in the environment because it’s strange.
I also tried looking around in the DevForum, but I couldn’t find a straightforward answer.
I’m so sorry I cannot help you.
I have noticed that in the script(s) nothing is using the ForwardAcceleration property so just change it to
wheel.CylindricalConstraint.MotorMaxAngularAcceleration = vehicle:GetAttribute("Car_ForwardAcceleration");
changing to that and the error doesnt occur anymore
Thank you for you suggestion but i already tried that
You helping was enough for me to get happy
Yeah i found the original creator of the file and he could not solve it as well. So I copied my entire game to the original file and published it as my main game. The problem itself is a mystery right now but we might reach some awnsers from sombody else in the future. Thank you (: