Roblox Studio:MarketplaceService:PromptProductPurchase() player 应该是 Player 类型。我该如何解决?

问题描述 投票:0回答:2

我在 roblox studio 上不断收到此错误:MarketplaceService:PromptProductPurchase() player should be of type Player。我如何解决它?这是代码

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer

local productid = 1340456024

local function promptPurchase()
    MarketplaceService:PromptProductPurchase(LocalPlayer, productid)
end

script.Parent.MouseButton1Click:Connect(promptPurchase())

我尝试更改函数定义,但它一直抛出相同的错误。

lua game-development roblox
2个回答
0
投票

你原来的标题错误是由于

LocalPlayer
变量为零引起的。那是因为您使用的是服务器端脚本,而不是在客户端运行的 LocalScript。
Players.LocalPlayer
仅存在于 LocalScripts 中。

除此之外,代码中唯一的其他问题是如何将函数传递给连接。您在

()
的末尾有
promptPurchase
调用函数,而不是传递函数引用。要解决您的问题,只需删除括号即可。

script.Parent.MouseButton1Click:Connect(promptPurchase)

0
投票

尝试使用'''MarketplaceService:PromptProductPurchase'''

© www.soinside.com 2019 - 2024. All rights reserved.