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