Vehicle Locking Script Help

local Car  = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent
local ClickDetector = script.Parent
local SFX = ClickDetector.Parent.SFX
local Locked = ClickDetector.Parent.Locked

ClickDetector.MouseClick:connect(function(plr) -- upon clicking
	if plr.Name == Car.Owner.Value then -- if the player is the owner
		if Locked.Value == false then
			Locked.Value = true
			SFX:Play()
			Car.Anchored = true
		else
			Locked.Value = false
			SFX:Play()
			Car.Anchored = false
		end
	else
	end
end)

Hey guys, trying to do a vehicle locking script where when the player clicks on a button, the vehicle anchors and the locked value becomes true after checking whether the player’s name matches the one in Car.Value, any idea why this doesn’t work?

Maybe because of ur big chain parents on first line (i always had issues with those even if it was correct maybe bugged)
Do u get any errors

Well other than not having a debounce this looks pretty straight forward. Are you getting any errors in the output window? Prints can help you figure out where it is going wrong..

ClickDetector.MouseClick:Connect(function(plr)

Shouldn’t matter for now, but that c should be a C.

For some reason nothing seems to be printing.. I’ve edited some things as I realised as Car.Owner is an attribute I have to do
local Owner = Car:GetAttribute("owner") instead. I also changed Car.Anchored to

local CarModel = Car:GetChildren()
for i,v in pairs(CarModel) do
				if v:IsA("BasePart") then
					v.Anchored = true
				end
				end

Still not sure what is going on lol

local ClickDetector = script.Parent
local SFX = ClickDetector.Parent.SFX
local DoorLocked = ClickDetector.DoorLocked
local Car = ClickDetector.Parent.Parent.Parent.Parent.Parent.Parent
local CarModel = Car:GetDescendants()
local Owner = Car:GetAttribute("owner")

ClickDetector.MouseClick:connect(function(plr) -- upon clicking
	print("Player Clicked")
	if plr == Owner.Value then -- if the player is the owner
		print("Owner found")
		if DoorLocked.Value == false then
			print("Door Locking")
			DoorLocked.Value = true
			SFX.Playing = true
			for i,v in pairs(CarModel) do
				if v:IsA("BasePart") or v:IsA("MeshPart") then
					v.Anchored = true
				end
				end
			
		elseif DoorLocked.Value == true then
			print("Door Unlocking")
			DoorLocked.Value = false
			SFX.Playing = true
			for i,v in pairs(CarModel) do
				if v:IsA("BasePart") or v:IsA("MeshPart") then
					v.Anchored = false
				end
			end
		end
		
	else
		print("Owner not found")
	end
end)

This is the full script now.

I have now updated the script to:

local ClickDetector = script.Parent
local SFX = ClickDetector.Parent.SFX
local DoorLocked = ClickDetector.DoorLocked
local Car = ClickDetector.Parent.Parent.Parent.Parent.Parent.Parent
local CarModel = Car:GetDescendants()
local Owner = Car:GetAttribute("owner")

ClickDetector.MouseClick:connect(function(plr) -- upon clicking
	print("Player Clicked")
	if typeof(Owner) == plr.Name then -- if the player is the owner
		print("Owner found")
		
		if DoorLocked.Value == false then
			print("Door Locking")
			DoorLocked.Value = true
			SFX.Playing = true
			for i,v in pairs(CarModel) do
				if v:IsA("BasePart") or v:IsA("MeshPart") then
					v.Anchored = true
				end
				end
			
		elseif DoorLocked.Value == true then
			print("Door Unlocking")
			DoorLocked.Value = false
			SFX.Playing = true
			for i,v in pairs(CarModel) do
				if v:IsA("BasePart") or v:IsA("MeshPart") then
					v.Anchored = false
				end
			end
		end
		
	elseif typeof(Owner) ~= plr.Name then -- if the player is not the owner
		print("Owner not found")
	end
end)

It finally prints, but it prints “Owner not found”

image
Made it print the vehicle owner’s name, as well as the name of the person clicking, yet it keeps saying owner not found

it’s not working because the player name isn’t equal to what the player type is when you use
typeof(Owner) it’s gonna return most likely “Instance” meaning the player instance, not the player name maybe try making the player.Name equal to the attribute or better yet the player ID

try printing typeof(Owner) and see what the attribute is set to

i realised Owner itself prints the name already, so i shouldve just done Owner == plr.Name instead of typeof(Owner) == plr.Name, thank you so much!

Good job.. Remember this, prints are super useful for debugging.