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

How do I make a gamepass and/or group door?

I want to make a part that allows gamepass owners or a certain rank to be able to go through it, but when I scripted it I get some errors, I'm an intermediate scripter.

Here is the script I made:

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		if marketplace:UserOwnsGamePassAsync(plr.UserId, gamepassidhere) or 
		plr:GetRankInGroup(groupid) >= 0 then
		script.Parent.CanCollide = false
		wait(2)
		script.Parent.CanCollide = true
		end
	end
end)

2 answers

Hii, here’s the Group Rank Door script!

--PUT THIS SCRIPT UNDER STARTERGUI!!!--

local Player = game.Players.LocalPlayer
local doorPart = game.Workspace.Door.Door
local groupId = --GROUPIDHERE
local minimumRank = 2

if Player:GetRankInGroup(groupId) >= minimumRank then
	print("Player is at or above minimum rank")
	doorPart.CanCollide = false
else
	print("Player is below minimum rank")
	doorPart.CanCollide = true
end

4 comments

0

changing it in server will change it for everyone

0

you probably shouldn't give entire scripts.

0

Also, there's no need to put it in StarterGui.

0

I’m not a good scripter yet ok? Lol

I suggest using a RemoteEvent in Replicated Storage

ServerScript:

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
        if marketplace:UserOwnsGamePassAsync(plr.UserId, gamepassidhere) or 
          if plr:GetRankInGroup(groupid) >= 0 then
             game.ReplicatedStorage.RemoteEvent:FireClient(plr)
         end
    end
end)

Local Script in StarterPlayerScripts:

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function()
    local door = workspace:FindFirstChild(“door”,true) —Change this to the name of the door
    door.CanColliide = false 
    wait(2)
    door.CanCollide = true
end)

If it’s fine, can you elaborate on the errors so i can adjust the script accordingly?

2 comments

0

 For ServerScript, lines 5th has a error with the "if" and for Local Script, it says "OnServerEvent can only be used on the server" 

0

sorry i changed it

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