I am trying to make a part that teleports if you have the game pass, but the script gives me an error that says that it couldn’t identify the UserId or something. Can anyone help?
local id = 0000000
local mps = game:GetService("MarketplaceService")
script.Parent.Touched:Connect(function(t)
local w = t:FindFirstChild("Humanoid")
local player = game:GetService("Players"):GetPlayerFromCharacter(t)
if mps:UserOwnsGamePassAsync(player.UserId, id) then
w.CFrame = workspace.Castle.sonicmorph.CFrame + Vector3.new(0, 5, 0)
else
mps:PromptPurchase(player.UserId, id)
end
end)
script.Parent.Touched:Connect(function(t) --t returns otherParts who touches this part
--to get a player you should do like this:
local plr = game.Players:GetPlayerFromCharacter(t.Parent) -- t.Parent the parent of otherPart that touched this part
if plr then -- making sure if it's a Player
--gamepass stuff
end
end)
Fixed Script:
local id = 0000000
local mps = game:GetService("MarketplaceService")
script.Parent.Touched:Connect(function(t)
--local w = t:FindFirstChild("Humanoid")
local player = game:GetService("Players"):GetPlayerFromCharacter(t.Parent)
if player and mps:UserOwnsGamePassAsync(player.UserId, id) then
w.CFrame = workspace.Castle.sonicmorph.CFrame + Vector3.new(0, 5, 0)
else
mps:PromptPurchase(player.UserId, id)
end
end)