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
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.
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)
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.
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.
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.