Roblox Lua 错误 Value is not a valid member of Player, I don't try accessing that though

我正在尝试在 Roblox 上制作一个游戏,前一段时间我遇到了一个错误,我找不到解决方法就放弃了,现在我再次开始尝试解决它。当我尝试检查玩家能否购买物品时,我遇到了错误 Value is not a valid member of Player,以下是我的代码中出现错误的部分

game:GetService("ReplicatedStorage"):WaitForChild("Shop"):WaitForChild("UpgradeClicks").OnServerEvent:Connect(function(player, price)
    if player.leaderstats.Views.Value <= price.Value then
        print("test")
    end
end)

以下是当你按下按钮后发生的代码

local RE = game:GetService("ReplicatedStorage").Shop.UpgradeClicks
local button = script.Parent
local price = script.Parent.Price
local player = game.Players.LocalPlayer

button.MouseButton1Click:Connect(function()
    RE:FireServer(player, price)
end)
点赞
用户13278101
用户13278101

尝试在不放置玩家变量的情况下调用fireserver。

2020-04-10 21:31:38
用户2860267
用户2860267

当你调用 FireServer() 时,调用它的玩家会自动添加为服务器回调中的第一个参数。

因此,到达服务器的参数列表是:玩家、玩家、整数值。这就是为什么说 Player.Value 不是有效的原因。

将你的按钮代码更改为不传入 LocalPlayer。

button.MouseButton1Click:Connect(function()
    RE:FireServer(price)
end)
2020-04-11 04:00:00