MeDerp
MeDerp

Reputation: 13

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

I am trying to make a game on Roblox and a while ago I ran into an error, I couldn't find a fix and gave up, and I just started trying to fix it again. When I try to check if the player can afford to buy the item, I get the error Value is not a valid member of Player, here's my code from where the error is coming from

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

Here's the code that happens when you press the button

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)

Upvotes: 1

Views: 2776

Answers (2)

Kylaaa
Kylaaa

Reputation: 7188

When you call FireServer() the player that calls it is automatically added as the first argument in the server callback.

So the argument list that is arriving at the server is : player, player, intValue. That's why it is saying that Player.Value isn't valid.

Change your button code to not pass in the LocalPlayer.

button.MouseButton1Click:Connect(function()
    RE:FireServer(price)
end)

Upvotes: 1

StasN
StasN

Reputation: 66

Try to call fireserver without putting in a player variable.

Upvotes: 1

Related Questions