If player.name = script.OwnerName?

So I have this script that i want to check if the players name is the name of the “ownername” value, and its not working? Any help?

local accepted = script.OwnerName
function check(p)
if p.Character.Name(accepted) then return true end
return false
end


script.Parent.ChildAdded:connect(function(child)
		if child:IsA("Weld") then
			if child.Part1 ~= nil then
				if child.Part1.Parent ~= nil then
					if game.Players:playerFromCharacter(child.Part1.Parent) ~= nil then
						


local player = game.Players:playerFromCharacter(child.Part1.Parent)
if check(player) then else child.Part1.Parent:BreakJoints() end

					end
				end
			end
		end
	end)

Where is this script? Are you sure the child is supposed to be a weld?

In order to check if an instance exists, use FindFirstChild
example:

if not workspace:FindFirstChild("Part") then print("no part") end

Its just saying "Attempt to call field ‘Name’ (a string value)

image

Try

if p.Character.Name == accepted then return true end

A couple things wrong here:

  1. You aren’t indexing the Value property of OwnerName, meaning it will always return false because you’re trying to compare an Instance and a string.
  2. You’re attempting to call Name instead of indexing it as a property, that’ll throw an error.

I’ve tidied up your script a little, this should work if my guesses towards what you’re doing is correct.

function check(p)
	return p.Name==script.OwnerName.Value
end

script.Parent.ChildAdded:connect(function(child)
	if child:IsA("Weld") then
		if child.Part1~=nil and child.Part1.Parent~=nil then
			local player=game.Players:GetPlayerFromCharacter(child.Part1.Parent)
			if player and not check(player) then
				player.Character:BreakJoints()
			end
		end
	end
end)
3 Likes