Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

teleport if player has gamepass?

Asked by 5 years ago
Edited 5 years ago

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

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

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)


0
the player isn't defined i think but the script wont teleport me retracee 68 — 5y
0
It is defined, what are you on about User#19524 175 — 5y
0
I don't know but the script won't teleport me I'm looking for mistakes right now retracee 68 — 5y
Ad

Answer this question