Hi Devs,I need help with something I wanna make so that when the player buys the VIP Gamepass he is able to pass thtough a Visible part blocking the way up to the 2nd floor Please Help!
Here are some things you may use:
Script:
local GamePassService = game:GetService('GamePassService')
local PlayersService = game:GetService('Players')
local door = script.Parent
local GamepassID = 10326802 -- change the ID to your gamepass
local JustTouched = {}
local function TeleportToOtherSide(character, hitPart)
local bottomOfDoor = door.CFrame.p - Vector3.new(0, door.Size.Y / 2, 0)
local inFrontOfDoor = bottomOfDoor + door.CFrame.lookVector * 3
local behindDoor = bottomOfDoor - door.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:PlayerHasPass(player, GamepassID) then
TeleportToOtherSide(player.Character, otherPart)
end
end
end
end
local function RemoveOldTouches()
for player, touchTime in pairs(JustTouched) do
if time() > touchTime + 0.3 then
JustTouched[player] = nil
end
end
end
door.Touched:connect(OnTouched)
while true do
RemoveOldTouches()
task.wait(1/30)
end
Localscript (Make sure streaming enabled is set false to use this, player must rejoin for the door to open):
local GamePassService = game:GetService('GamePassService')
local door = workspace.Baseplate -- enter the location of it
local GamepassID = 10326802 -- change the ID to your gamepass
if GamePassService:PlayerHasPass(game.Players.LocalPlayer, GamepassID) then
door.Transparency = 1
door.CanCollide = false
end
Im going to use the second option I have two question
1.Is it a script or localscript
2.Wheres should i put the script
The second option is a LocalScript.
if you use the second option then put the script in StarterPlayer > StarterPlayerScripts
I have mentioned that the second option is a LocalScript in the reply of I sent for the code
Ok thank you very much For your help.
1 Like