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?
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
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)
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”
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