So i've got this script that is supposed to teleport anyone who owns this gamepass to a certain location but whenever anyone steps on it, it teleports the people with the gamepass. If anyone can rewrite this to get it working that would be appreciated!
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local gamePassID = 2003331 -- Change this to your game pass ID
function onPlayerSpawned(player)
local hasPass = false
-- Check if the player already owns the game pass
local success, message = pcall(function()
hasPass = MarketplaceService:UserOwnsGamePassAsync(player.userId, gamePassID)
print("Has Game Pass")
end)
-- If there's an error, issue a warning and exit the function
if not success then
warn("Error while checking if player has pass: " .. tostring(message))
return
end
if hasPass == true then
script.Parent.Touched:Connect(function(Hit)
game.Workspace:WaitForChild(player.Name).HumanoidRootPart.CFrame = CFrame.new(212.15, 8.533, -130.643)
end)
end
end
game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function()
onPlayerSpawned(player)
end)
end)
-- Connect 'PlayerAdded' events to the 'onPlayerAdded()' function
Players.PlayerAdded:Connect(onPlayerSpawned)

3 comments
Do you mean it teleports the people who dont have the gamepass? because i dont get your description.
Let's say there is me in the game(who owns gamepass) and a noob who doesn't own it. If the noob steps on the teleport it won't affect him but it will teleport me to the other place.
Don't ask for us to do your work, we aren't slaves.