Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

teleport if player has gamepass?

I'm not sure what's going wrong

local PassId = 4835177
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")
local player = game.Players.LocalPlayer
local bloxy = workspace:WaitForChild("itemgiver1")
local debounce = false


script.Parent.Touched:connect(function(hit)
	local user = hit.Parent
	 if MarketplaceService:UserOwnsGamePassAsync(user.UserId, PassId) then 
 if hit.Parent:FindFirstChild('Humanoid') then
  hit.Parent.Torso.CFrame = CFrame.new(1999971.875, 53.506, -21.966)
hit.Parent.UpperTorso.CFrame = CFrame.new(1999971.875, 53.506, -21.966)
end
else
 MarketplaceService:PromptGamePassPurchase(user, PassId)
 end
	end)


1 answer

✓ Accepted answer

###LocalPlayer is nil on the server. It can only be used on the client. Get the player with GetPlayerFromCharacter.

local PassId = 4835177
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local bloxy = workspace:WaitForChild("itemgiver1")
local debounce = false
local pos = CFrame.new(1999971.875, 53.506, -21.966)
local getPlayerFromCharacter
local player

getPlayerFromCharacter = function(model)
    local plr = Players:GetPlayerFromCharacter(model)
    
    if plr then 
        return plr
    else
        return nil 
    end
end

script.Parent.Touched:Connect(function(hit) -- :connect is deprecated, switch to :Connect
    player = getPlayerFromCharacter(hit.Parent)
    
    if player then
        if MarketplaceService:UserOwnsGamePassAsync(player.UserId, PassId) then -- if they have the gamepass
            player.Character:SetPrimaryPartCFrame(pos)
    else
        MarketplaceService:PromptGamePassPurchase(player, PassId) -- if they dont teleport them
        end
    end
end)


3 comments

0

the player isn't defined i think but the script wont teleport me

0

It is defined, what are you on about

0

I don't know but the script won't teleport me I'm looking for mistakes right now

This discussion is preserved as it was. New answers, comments, and votes are closed.