Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

attempt to index local 'price' (a number value)?

Asked by 6 years ago

Error:

19:21:08.240 - ServerScriptService.Shop:4: attempt to index local 'price' (a number value)

Local:

local plr = game.Players.LocalPlayer
local price = script.Parent.Price
script.Parent.Item.Changed:Connect(function()
    script.Parent.Parent.Info.Item.Text = script.Parent.Item.Value
    script.Parent.Parent.Info.Price.Text = "Price: "..script.Parent.Price.Value
end)

script.Parent.Parent.Info.TextButton.MouseButton1Click:Connect(function()
    if plr.leaderstats.Money.Value >= script.Parent.Price.Value then
    local func = game.ReplicatedStorage.BuyRequest:InvokeServer(price.Value)
    if func == "Bought" then
        script.Parent.Parent.Info.TextButton.Text = "Bought!"
    end
    else
        script.Parent.Parent.Info.TextButton.Text = "Lamo, Not Enough Money"
    end
end)

Server:

game.ReplicatedStorage.BuyRequest.OnServerInvoke =function(plr, price)
    local money = game.Players:FindFirstChild(plr.Name).leaderstats.Money
    money.Value = money.Value-price.Value
    return "Bought"
end

Im trying to send the player and a number value through a remote function.

0
Your remotes are VERY insecure. You should be checking if they have enough money **on the server**. green271 635 — 6y
0
Additionally, why are you doing game.Players:FindFirstChild(plr.Name) when the player object is literally being handed to you? User#19524 175 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

You are sending the value stored in the price value object through the remote event (price.Value) rather than sending the value object itself. This is fine - you just have to change line 3 in your server script to:

money.Value = money.Value-price

This will fix the error you are having, but as green271 stated in the comments, you should always check on the server if the player has enough money to do what they are trying to do. You can never trust what the client is telling you, and need to verify everything on the server.

0
ok CarMaster17 28 — 6y
Ad

Answer this question