Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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.

2 comments

0

Your remotes are VERY insecure. You should be checking if they have enough money on the server.

0

Additionally, why are you doing game.Players:FindFirstChild(plr.Name) when the player object is literally being handed to you?

1 answer

✓ Accepted answer

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.

1 comment

0

ok

This discussion is preserved as it was. New answers, comments, and votes are closed.