Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

VIP door doesn't work, tried 2 scripts so far, why doesn't it work?

Asked by 7 years ago

So I used Nikilis' VIP script and ROBLOX's VIP script but for some reason, both doesn't work and I truly don't get why it doesn't', so here's the script:

-- Recommended: Place this in the VIP Door
----------------------------------------------------------------------- 
PassOrShirtID = 837872254 -- Change this to your asset/shirt/badge/pass ID
Door = script.Parent -- Change this to the door (if needed)
OpenTime = 1 -- Change how long you want the door open
Prompt = true -- true = if the player doesn't have the item, prompt a screen to let them buy it. false = kill the player.
-----------------------------------------------------------------------
-- Made by Nikilis --


--Do not touch below--
Serv = game:GetService("BadgeService")
MServ = game:GetService("MarketplaceService")
if not _G.Players then
    _G.Players = {
        [PassOrShirtID] = {};
    }
    print("Players Created")
elseif not _G.Players[PassOrShirtID] then
    _G.Players[PassOrShirtID] = {};
    print("Players.Pass created")
end

Table = _G.Players[PassOrShirtID]

function CheckPlayer(player2)
    for i = 1,#Table do
        if Table[i] == player2 then
            return true
        end
    end
    return false
end

Door.Touched:connect(function(hit)
    if game.Players:GetPlayerFromCharacter(hit.Parent) then
        player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if Serv:UserHasBadge(player.userId,PassOrShirtID) or CheckPlayer(player) then
            Door.CanCollide = false; Door.Transparency = 0.5;
            wait(OpenTime);
            Door.CanCollide = true; Door.Transparency = 0;
        else
            if Prompt then -- nikilis
                MServ:PromptPurchase(player,PassOrShirtID)
                h = player.Character:FindFirstChild("Humanoid")
                if h then h.WalkSpeed = 0 end
                local con;
                con = MServ.PromptPurchaseFinished:connect(function(ply,asset,purch)
                    if ply == player and asset == PassOrShirtID then
                        con:disconnect()
                        if purch then
                            if h then h.WalkSpeed = 16 end
                            table.insert(Table,player)
                        else
                            player.Character:BreakJoints()
                        end
                    end 
                end)
            else
                player.Character:BreakJoints()
            end
        end
    end
end)




















-- Made by Nikilis

I don't get any errors either, it's so strange.

0
Check out the ROBLOX sets; one of them is a VIP Door that works. theofficialsy 36 — 7y
0
I've already tried it, it didn't work for me but someone already helped me, thanks! Ber_ries 18 — 7y

1 answer

Log in to vote
0
Answered by
cabbler 1942 Moderation Voter
7 years ago

Hmm? This works fine when I test it in a local server. No matter what, you should get rid of badge service since this is meant to use any asset. It makes things simpler too. Also I see know reason to use _G if it stays in one script.

Things I notice as I clean this up:

  • owners should be stored in a much neater local dictionary

  • door open should be a function

  • purchase finished should be handled in one place

  • in touch function, variables should be better defined

Here is what I recommend. If it doesn't work then there must be some other crazy issue that would be hard to even diagnose.

-- Recommended: Place this in the VIP Door
----------------------------------------------------------------------- 
PassOrShirtID = 538413003 -- Change this to your asset/shirt/badge/pass ID
Door = script.Parent -- Change this to the door (if needed)
OpenTime = 1 -- Change how long you want the door open
Prompt = true -- true = if the player doesn't have the item, prompt a screen to let them buy it. false = kill the player.
-----------------------------------------------------------------------

MServ = game:GetService("MarketplaceService")
owners = {}
function openDoor()
    Door.CanCollide = false; Door.Transparency = 0.5
    wait(OpenTime)
    Door.CanCollide = true; Door.Transparency = 0
end

MServ.PromptPurchaseFinished:connect(function(ply,asset,purch)
    if asset == PassOrShirtID then
        if purch then
            owners[ply]=true
            pcall(function() ply.Character.Humanoid.WalkSpeed = 16 end)
        else
            ply.Character:BreakJoints()
        end
    end 
end)

Door.Touched:connect(function(hit)
    local char = hit.Parent
    local player = game.Players:GetPlayerFromCharacter(char)
    if player then
        if owners[player] then
            openDoor()
        elseif MServ:PlayerOwnsAsset(player,PassOrShirtID) then
            owners[player]=true
            openDoor()
        else
            if Prompt then
                MServ:PromptPurchase(player,PassOrShirtID)
                local h = char:FindFirstChild("Humanoid")
                if h then h.WalkSpeed = 0 end
            else
                char:BreakJoints()
            end
        end
    end
end)
Ad

Answer this question