local btn = script.Parent
local RemoteEvent = game.ReplicatedStorage.ItemBought
local PaperClipValue = script.Parent.Parent.Parent.BuyFrame.Buy.IPPPaperClipalue
local Cash = game.Players.LocalPlayer.Values.Cash
local Item = game.Players.LocalPlayer.Values.PaperClips
btn.MouseButton1Down:Connect(function()
if PaperClipValue.Value*5 > Cash.Value then
print("No sir you need more cash")
elseif PaperClipValue.Value*5 <= Cash.Value then
RemoteEvent:FireServer(PaperClipValue.Value,5,Item)
end
end)
Script 2 (One with Error) Handles the Adding and Subtracting of Values
My initial response addressed this error and how to fix it. The error is that āItembeingpurchasedā is nil.
To clarify:
You canāt index objects with other objects.
I see you defined an Itembeingpurchased variable but that is a reference to the item object. You canāt index objects with variables or other objects. You have to specify its exact name or search with strings using :FindFirstChild() / :WaitForChild(). āItembeingpurchasedā is what is being searched for in the plr.Values folder since that is the exact name you provided, and is returning nil since it canāt find an item called āItembeingpurchasedā.
but I do not recommend that because theres a chance your Itembeingpurchased variable could go nil at any time, breaking the script. Or it could possibly not locate an item with Itembeingpurchasedās Name, then it would cause a similar error trying to index nil with āValueā.
I recommend following my initial reply:
local btn = script.Parent
local RemoteEvent = game.ReplicatedStorage.ItemBought
local PaperClipValue = script.Parent.Parent.Parent.BuyFrame.Buy.IPPPaperClipalue
local Cash = game.Players.LocalPlayer.Values.Cash
local Item = game.Players.LocalPlayer.Values.PaperClips
+ local ItemName = Item.Name
btn.MouseButton1Down:Connect(function()
if PaperClipValue.Value*5 > Cash.Value then
print("No sir you need more cash")
elseif PaperClipValue.Value*5 <= Cash.Value then
+ RemoteEvent:FireServer(PaperClipValue.Value,5,Item,ItemName)
end
end)
why are you creating a variable for item when it already exists (and not even using it)
that is extra processing power for absolutely zero reason
and the error is probably explaining itself very well, there is no value called itembeingpurchased and i dont see you creating it anywhere in your scripts
This is because it wasnāt working with Item so I decided to try another stupid way that didnāt work so I came to deform and forgot to change it. Sorry Im dumb.
Thank you so much for your help Iām so sorry that I suck at scripting one day I hope to get better thanks for helping me understand more even though at times it might have been difficult for you to understand me.
I edited the script a little but for the most part you guided me well.