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

How to create a working door for VIP-room? [Self answered in answers]

Asked by 3 years ago
Edited 3 years ago

Hello! I've made a vip room, and a vip door, which must tp into that room. But the door teleports only to the roof. Here's the script I've used

--------------------
--| WaitForChild |--
--------------------

-- Waits for parent.child to exist, then returns it
local function WaitForChild(parent, childName)
    assert(parent, "ERROR: WaitForChild: parent is nil")
    while not parent:FindFirstChild(childName) do parent.ChildAdded:wait() end
    return parent[childName]
end

-----------------
--| Variables |--
-----------------

local GamePassService = game:GetService('MarketplaceService')
local PlayersService = game:GetService('Players')

local VipDoor = script.Parent

local GamePassIdObject = script:WaitForChild( 'GamePassId')

local JustTouched = {}

-----------------
--| Functions |--
-----------------

-- Finds out which side the player is on and teleports them to the other
local function TeleportToOtherSide(character, hitPart)
    local bottomOfDoor = VipDoor.CFrame.p - Vector3.new(0, VipDoor.Size.Y / 2, 0)
    local inFrontOfDoor = bottomOfDoor + VipDoor.CFrame.lookVector * 3
    local behindDoor = bottomOfDoor - VipDoor.CFrame.lookVector * 3

    local distanceToFront = (inFrontOfDoor - hitPart.Position).magnitude
    local distanceToBack = (behindDoor - hitPart.Position).magnitude
    if distanceToFront < distanceToBack then
        character:MoveTo(behindDoor)
    else
        character:MoveTo(inFrontOfDoor)
    end
end

-- When a player with the game pass touches the door, teleport them to the other side
local function OnTouched(otherPart)
    if otherPart and otherPart.Parent and otherPart.Parent:FindFirstChild('Humanoid') then
        local player = PlayersService:GetPlayerFromCharacter(otherPart.Parent)
        if player and not JustTouched[player] then
            JustTouched[player] = time()
            if GamePassService:UserOwnsGamePassAsync(player.userId, GamePassIdObject.Value) then
                TeleportToOtherSide(player.Character, otherPart)
            end
        end
    end
end

-- Removes old entries in JustTouched
local function RemoveOldTouches()
    for player, touchTime in pairs(JustTouched) do
        if time() > touchTime + 0.3 then
            JustTouched[player] = nil
        end
    end
end

--------------------
--| Script Logic |--
--------------------

VipDoor.Touched:connect(OnTouched)

while true do
    RemoveOldTouches()
    wait(1/30)
end

I've also used intvalue. Is there another way to make the vip door, like if u have the game pass, make a script which gives ability to go through the wall?

0
uh u could destroy the door BulletproofVast 1033 — 3y
0
Bad idea but okay? Xapelize 2658 — 3y

3 answers

Log in to vote
0
Answered by
Xapelize 2658 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago
local Door = script.Parent
local MarketplaceService = game:GetService("MarketplaceService")
local GamePassId = 15657584 -- Change the number to 15664177 in Mega VIP

Door.Touched:Connect(function()
    if MarketplaceService:UserOwnsGamePassAsync(game.Players.LocalPlayer, GamePassId)
            Door.Transparency = 1
            Door.CanCollide = false
        else
            MarketplaceService:PromptGamePassPurchase(game.Players.LocalPlayer, GamePassId)
    end
end
0
Sorry for alot of troubles. My brain when it's at some times it doesn't seems like following what I do. Now this might work Xapelize 2658 — 3y
0
Lemme try.. nikitos54327 70 — 3y
0
you forgot to type "then" at 5 and a ")" in end nikitos54327 70 — 3y
0
I fixed, but it still not working, also I made my own nikitos54327 70 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
local function TeleportToOtherSide(character, hitPart)
    local bottomOfDoor = VipDoor.CFrame.p - Vector3.new(0, VipDoor.Size.Y / 2, 0)
    local inFrontOfDoor = bottomOfDoor + VipDoor.CFrame.lookVector * 3
    local behindDoor = bottomOfDoor - VipDoor.CFrame.lookVector * 3

    local distanceToFront = (inFrontOfDoor - hitPart.Position).magnitude
    local distanceToBack = (behindDoor - hitPart.Position).magnitude
    if distanceToFront < distanceToBack then
        character:SetPrimaryPartCFrame(CFrame.new(behindDoor))
    else
        character:SetPrimaryPartCFrame(CFrame.new(inFrontOfDoor))
    end
end


0
The script isn't working nikitos54327 70 — 3y
Log in to vote
0
Answered by 3 years ago

Answering on own question:

-----------------------------------------------------------------------------------------------

ItemID = " " -- Change it for the ID of the Gamepass/T-Shirt.
OpenTime = 0.9 -- The time the door is open for.
OpenTrans = 1 -- The transparency of the door when it is open.
CloseTrans = 0.85 -- The transparency of the door when it is closed.
BuyGUI = true -- Set to false to stop the BuyGUI appearing.
KillOnTouch = true -- Set to false to stop players being killed when they touch it.

-----------------------------------------------------------------------------------------------

Door = script.Parent
Serv = game:GetService("BadgeService")
MServ = game:GetService("MarketplaceService")
if not _G.Players then
    _G.Players = {[ItemID] = {}}
elseif not _G.Players[ItemID] then
    _G.Players[ItemID] = {}
end

Table = _G.Players[ItemID]

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 MServ:UserOwnsGamePassAsync(player.userId,ItemID) or CheckPlayer(player) then
            Door.CanCollide = false Door.Transparency = OpenTrans
            wait(OpenTime)
            Door.CanCollide = true Door.Transparency = CloseTrans
            else
            Door.CanCollide = true Door.Transparency = CloseTrans
            if BuyGUI == true then
                MServ:PromptGamePassPurchase(player,ItemID)
                h = player.Character:FindFirstChild("Humanoid")
                if h then
                    h.WalkSpeed = 0 end
                    local con
                    con = MServ.PromptGamePassPurchaseFinished:connect(function(ply,asset,purch)
                    if ply == player and asset == ItemID then
                        con:disconnect()
                        if purch then
                            if h then
                                h.WalkSpeed = 16 end
                                table.insert(Table,player)
                                elseif KillOnTouch == true then
                                Door.CanCollide = true Door.Transparency = CloseTrans
                                player.Character:BreakJoints()
                            end
                        end 
                    end)
                elseif KillOnTouch == true then
                Door.CanCollide = true Door.Transparency = CloseTrans               
                player.Character:BreakJoints()
            end
        end
    end
end)

Answer this question