如何在 Roblox 中使用游戏通行证传送玩家

我尝试过一些教程,但是还没有找到解决方法。

  local id = 1180578480
local marketService = game:GetService("MarketplaceService")
function onTouched(m)
    p = m.Parent:findFirstChild("Humanoid")
    if marketService:UserOwnsGamepassAsync(user.UserId, id) then
        if p ~= nil then
            p.Torso.CFrame=CFrame.new(0,8,9)
        end
    end
    end
script.Parent.Touched:connect(onTouched)

原文链接 https://stackoverflow.com/questions/70010849

点赞
stackoverflow用户13636499
stackoverflow用户13636499

首先,请确保 id 设置为游戏通行证 id - 它似乎有点过高。

请记住,Lua 是大小写敏感的,因此需要使用 FindFirstChild 而不是 findFirstChild,UserOwnsGamePassAsync 而不是 UserOwnsGamepassAsync。

记住你有哪些变量以及它们正在存储什么 - 你还没有定义一个用户变量,而你在第 5 行中正在使用一个,并且你正在尝试获取一个 humanoid 的 Torso 而不是字符。

local id = 1180578480
local marketService = game:GetService("MarketplaceService")

function onTouched(m)
    local p = game.Players:GetPlayerFromCharacter(m.Parent)
    if p then
        if marketService:UserOwnsGamePassAsync(p.UserId, id) then
            p.Character.Torso.CFrame=CFrame.new(0,8,9)
        end
    end
end

script.Parent.Touched:Connect(onTouched)
2021-11-20 11:47:16