Roblox gamepass prompt not showing up

我正在尝试制作一个那些愚蠢好笑的 Roblox 游戏,游戏标题全部小写之类的。这个游戏的前提是你必须为任何事情付费;走路、跳跃、打开门等等。我编写了一个下列功能的脚本:首先它会检查你是否已拥有游戏通行证,然后如果你没有游戏通行证,在你按下 w、a、s 或 d 键时,它将打开购买游戏通行证的提示。我曾试图运行打印语句以查看是游戏通行证提示调用未起效还是诸如按键检测之类的其他问题,但都无济于事。(顺便说一下,它在一个本地脚本中,并带有一个名为“walkspeednew”的已停用脚本,它的作用是在你购买了游戏通行证后将你的走路速度设为正常值。名为“WalkSpeed”的脚本在游戏启动时运行,并将你的走路速度设置为0。)

local ps=game:GetService("Players")
local gamePassId=26063683
ps.PlayerAdded:Connect(function(player)
    local hasPass=false
    local success,message=pcall(function()
        hasPass=MarketplaceService:UserOwnsGamepassAsync(player.UserId,gamePassId)
    end)
    if not success then
        warn('gamepass loading error')
        return
    end
    if hasPass then
        game.Workspace.WalkSpeed:Destroy()
        script.walkspeednew.Disabled=false
    end
end
UserInput.InputBegan:Connect(function(input,gameProccesedevent)
    if not hasPass then
        if input.KeyCode==Enum.KeyCode.W or input.KeyCode==Enum.KeyCode.A or input.KeyCode==Enum.KeyCode.S or input.KeyCode==Enum.KeyCode.D then
            local player=game.Players.LocalPlayer
            Game:GetService("MarketplaceService"):PromptPurchase(player,gamePassId)
        end
    end
end)

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

点赞
stackoverflow用户15794497
stackoverflow用户15794497

使用 UserInput 并不方便。Humanoid有一个名为MoveDirection的属性,它作为一个单位矢量,确定了玩家移动的方向。你可以访问Magnitude属性,检查它是否大于0,以知道是否存在活跃的移动,而不依赖于他们的HumanoidStateType或UserInput。

2021-12-15 07:47:44