owner = script.Parent.OwnerName local player = game.Players.LocalPlayer local mouse = player:GetMouse() mouse.Button1Down:connect(function(hit) local check = hit.Parent:FindFirstChild("Humanoid") local thisplr = game.Players:findFirstChild(hit.Parent.Name) if owner.Value == thisplr then script.Parent.Locked = false else script.Parent.Locked = true end end)
So this is a LocalScript, this localscript is inside a part called "brick". The brick has stringvalue of OwnerName and value of Player1, i just directly Assigned it for testing. So, When you click it and your name is not Player1 the brick will remain locked, but if your name is Player1 then locked is false. But it's not working. Please help.
First off, please fix your title. Your question title would most likely not attract scripters, since it's too broad. To detect when someone clicked a Part, you'd used the MouseClick Event. To do that, you'd need to insert a ClickDetector into the part. Also, there's no need for the script to be a LocalScript. With that in mind, here is your fixed script:
owner = script.Parent.OwnerName script.Parent.ClickDetector.MouseClick:connect(function(plr) if plr.Name == owner.Value then script.Parent.Locked = false else script.Parent.Locked = true end end)
One last note: Be sure to search your question before asking it. I've answered these type of questions numerous time. Instead of including the "Locked = true" part, just search about a ClickDetector, or how to get who clicked a click detector.