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)
Put your touched event outside of the function, and check like this:
part.Touched:Connect(function(hit) local hum = hit.Parent:FindFirstChild("Humanoid") if hum and hum.Health > 0 then local plr = game:GetService("Players"):GetPlayerFromCharacter(hum.Parent) --check if owns gamepass here, you have a plr variable and now check if owns gamepass, if yes then teleport, if not ignore end end)
Closed as Not Constructive by User#19524
This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.
Why was this question closed?