Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Car value not disconnecting?

I'm trying to make a remote control car tool, it's supposed to do that when you unequip the tool, the car objectvalue is set to nil (nothing) and the "RemoteControlConnected" value in the car is supposed to be false. But for some reason, nothing happens. The "RemoteControlConnected" is not set to false and the ObjectValue is not set to nil, it's still set to the car? It's a serverscript inside an object value, parented to a tool. Why is this happening?

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

tool.Unequipped:Connect(function()
	if value ~= nil then
		print("Remote unequipped with vehicle connected, disconnecting...")
		for i,v in pairs(value:GetDescendants()) do
			pcall(function()
				if v.Name == "OwnerName" then
					v.TextLabel.Text = "Not connected"
				end
			end)
		end
		value.RemoteControlConnected.Value = false
		wait(3)
		value = nil
	end
end)

1 answer

✓ Accepted answer

script.Parent.VehConnected.Value will give you a value not an object

so

local value = script.Parent.VehConnected.Value

Will actually set whatever Value is in VehConnected to the variable value, not the object itself

You might want to type

local value = script.Parent.VehConnected

Then line 05 would be

 if value.Value ~= nil then

And then in line 16 You type in

value.Value = nil

This discussion is preserved as it was. New answers, comments, and votes are closed.