Help with my script

So i created a “CreatorOnlyDoor” and i made the script but the game in a group and i dont know how to make the script let pass the founder of the group

Code:

function onTouched(hit)

local h = hit.Parent:findFirstChild("Humanoid")

if h ~= nil then

if game.Players:findFirstChild(hit.Parent.Name).userId == game.CreatorId then

script.Parent.Transparency = .3

script.Parent.CanCollide = false

wait(3)

script.Parent.Transparency = 0

script.Parent.CanCollide = true

else

hit.Parent:BreakJoints() – Kills them if their not the Creator

end

end

end

script.Parent.Touched:connect(onTouched)

Add your userid to a whitelist. That whitelist can be a table.

local whitelist = {myuserId};

if whitelist[game:GetPlayerFromCharacter(hit.Parent).UserId] then
    -- do stuff
end
1 Like

add a line like so:

if game.CreatorId == game:GetPlayerFromCharacter(hit.Parent).UserId then
    --let them in
end

EDIT: I noticed you have already typed that.

The issue here is, you have typed FindFirstChild as “findFirstChild”, and UserId as “userId”. Correct the spelling, and it should work.

1 Like

You should use this to find the group owner ID.

Example:

local Group = game:GetService(“GroupService”):GetGroupInfoAsync(groupId)
local Owner = Group.Owner
local OwnerId = Owner.Id

3 Likes

It didnt work… I fixed the “FindFirstChild” but it didnt work…

Have you fixed the UserId spelling? If not, could you try that for me?

game.CreatorId returns a group Id regardless. Changing the spelling of these won’t fix anything if he’s trying to use his own userId (or whoever the group owner is). You can utilize a player:GetRankInGroup() or @korky5000’s approach.

EDIT: Utilize the whitelist if you want specific people to access it. A general group rank gives it to whoever holds the role.

1 Like

No. It dont work i just tried it tho… I fixed the FindFirstChild and UserId spelling

This code should work:

local Players = game:GetService("Players")
local GroupId = 123
local function onTouched(hit)
	local h = hit.Parent:FindFirstChild("Humanoid")
	local Player = Players:GetPlayerFromCharacter(hit.Parent)
	local GroupRank = Player:GetRankInGroup(GroupId)
	if GroupRank == 255 then
		script.Parent.Transparency = .3
		script.Parent.CanCollide = false
		wait(3)
		script.Parent.Transparency = 0
		script.Parent.CanCollide = true
	else
		hit.Parent:BreakJoints() -- Kills them if their not the Creator
	end
end
script.Parent.Touched:connect(onTouched)
4 Likes
local AllowedUsers = {

["PlayerName1"] = true,

["PlayerName2"] = true,

["JakyeRU"] = false

}

function onTouched(hit)

local Humanoid = hit.Parent:FindFirstChild("Humanoid")

local Username = hit.Parent.Name

if Humanoid ~= nil then

if AllowedUsers[Username] then

script.Parent.Transparency = .3

script.Parent.CanCollide = false

wait(3)

script.Parent.Transparency = 0

script.Parent.CanCollide = true

else

hit.Parent:BreakJoints()

end

end

end

script.Parent.Touched:Connect(onTouched)

Use this code if you want to make the door for certain players.

1 Like

@snorebear

You forgot the game:GetService("Players") over there. As well, make sure that in an actual environment you’re appropriately checking what you’re getting. Imagine if you have a model hierarchy where a piece of, say, armour touches the door instead of a limb. Your object hierarchy would look like this:

Model Character
   Limbs
   Model Armour
      BasePart ArmourPart

hit.Parent, if hit is ArmourPart, would return the Armour model. You’d then be passing this to GetPlayerFromCharacter which would give you a nil value. In addition to that, you directly operate on the return value by using .UserId right after. If the value is nil, that script will throw an error.

Only in a group game. You can check the CreatorType to see whether it’s a group-owned place or a user-owned place. See the code example in this article.


@AbiZinho

The spelling in this case wouldn’t matter because these properties still exist and can be used. The difference is that they’re deprecated and the PascalCase versions of these methods are the ones that should be used. They’re deprecated, but not removed - avoiding the usage of deprecated items in new code is good practice.

2 Likes

You should add debounce to your script.

oof posts must be 50 chars…

1 Like

Yes. Debounce would be better but I have just fixed the check from his original script.

2 Likes