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

Why isn't this owner only door (door that only lets the owner of the game go through it) working?

So bassically I was trying to make it so that when I (which is represented by my UserId) touch the part that this script is in, the part goes transparent, and I can walk through it.

script.parent.Touched:connect(function(hit)
	if hit.UserId == "34310670" then
		print 'Hello, EpicLilC'
		script.parent.Transparency = .5
		script.parent.CanCollide = false
	end
end)

How come this script doesn't work?

1 answer

✓ Accepted answer

There are a few problems here.

First off, the "hit" is a BasePart, not a Player. That part could be the handle of an accessory, the Right leg, or anything. You must first check if it has a humanoid, then check if it is a player.

script.parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChildOfClass("Humanoid") then -- Checks if it has a humanoid
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent) -- Gets the player associated with the character
	if plr then -- Make sures it is actually there
		if plr.UserId == 34310670 then -- Makes sure it has the correct userid
        		print 'Hello, EpicLilC'
        		script.Parent.Transparency = .5
        		script.Parents.CanCollide = false
		end
	end
    end
end)

Second, UserId is an int, not a string, as you put in the code. Lastly, it is Parent, not parent.

Hope this helps!

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