I am encountering an issue where it seemingly is trying to expect a value despite there is an or inbetween so it can be either one, am I maybe not understanding the OR statement correctly? Or is it another issue. Many thanks in advance!
if raycastResult then
if raycastResult.Instance == game.Workspace.carAI.trafficLightSys or raycastResult.Instance.Name == "Car" then
if raycastResult.Instance.Stop.Value == true or raycastResult.Instance.Values.Stopped.Value == true then
tween:Pause()
script.Parent.Values.Stopped.Value = true
else
script.Parent.Values.Stopped.Value = false
game.Workspace.carAI.trafficLightSys.CarsPassing.Value = true
tween:Play()
end
end
end
It’s possible that Instance.Values doesn’t even exist. Make sure that Instance.Values actually does exist before trying to run the conditional statement, preferably with another conditional to check raycastResult.Instance:FindFirstChild("Values")?
That’s not what the error says.
The error says ‘Values’, not ‘value’.
It’s not expecting a value, it’s expecting a child of script.Parent called Values.
script.Parent.Values -- this does not exst and thus is causing an error
And as a piece of advice: you should probably not name any variables practically identical to any of Roblox’ data types… If you had named it ‘ValueArray’ or something similar, you probably wouldn’t have misdiagnosed the error!
Weird, doing that it still shows up. Does it need to be there before? Since let me show the full script to maybe give a better idea:
local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(
script.Parent.carValues.Speed.Value,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
0,
false,
0
)
local properties = {
Position = script.Parent.carValues.designatedEndpoint.Value.Position
}
local tween = tweenService:Create(script.Parent, tweenInfo, properties)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {script.Parent}
tween:Play()
while true do
local raycastResult = workspace:Raycast(script.Parent.front.WorldPosition, Vector3.new(6,0,0), raycastParams)
local rearResult = workspace:Raycast(script.Parent.back.WorldPosition, Vector3.new(-6,0,0), raycastParams)
if raycastResult then
if raycastResult.Instance == game.Workspace.carAI.trafficLightSys or raycastResult.Instance.Name == "Car" then
if raycastResult.Instance.Stop.Value == true or raycastResult.Instance:FindFirstChild("carValues").Stopped.Value == true then
tween:Pause()
script.Parent.carValues.Stopped.Value = true
else
script.Parent.carValues.Stopped.Value = false
game.Workspace.carAI.trafficLightSys.CarsPassing.Value = true
tween:Play()
end
end
end
if rearResult then
if rearResult.Instance == game.Workspace.carAI.trafficLightSys then
game.Workspace.carAI.trafficLightSys.CarsPassing.Value = false
end
end
tween.Completed:Connect(function()
script.Parent.Parent:Destroy()
end)
wait(0.1)
end
When using FindFirstChild, you have to ensure that it actually returns a result.
I.e
local result = raycastResult.Instance
local hasStop = result:FindFirstChild("Stop")
local hasCarValues = result:FindFirstChild("carValues")
if (hasStop and hasStop.Value) or (hasCarValues and hasCarValues.Stopped.Value) then
-- Code
end