So I was trying to make a gamepass door for me and my friends resort hotel game, but for whatever reason cannot get it to work.
The actual error: 13:42:10.074 - Unable to cast value to Object 13:42:10.075 - Stack Begin 13:42:10.075 - Script 'Workspace.VIP Door.VIP Door', Line 53 13:42:10.075 - Stack End
Script:
-- 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
local GamePassService = game:GetService('MarketplaceService') local PlayersService = game:GetService('Players')
local VipDoor = script.Parent
local GamePassIdObject = WaitForChild(script, 'GamePassId')
local JustTouched = {}
-- 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
local xxxxx = false -- 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 xxxxx == false then GamePassService:PromptGamePassPurchase(game.Players.LocalPlayer.UserId, 4795082) end if GamePassService:UserOwnsGamePassAsync(player.userId, script.GamePassId.Value) then TeleportToOtherSide(player.Character, otherPart) local xxxxx = true 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
VipDoor.Touched:connect(OnTouched)
while true do RemoveOldTouches() wait(1/30) end