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

Can someone explain to me why my script for a buy button in my tycoon is not working?

Hi, so I am making a tycoon and I have ran into a problem with a script for my buy button here is the code

repeat wait() until script.Parent.Product.Value ~= nil
local product = script.Parent.Product.Value:clone()
script.Parent.Product.Value:Remove()
price = script.Parent.Price.Value

script.Parent.Head.Touched:connect(function(hit)
	local char = hit.Parent
	if char:FindFirstChild("Humanoid") and game.Players:GetPlayerFromCharacter(char) then
		local plr = game.Players:GetPlayerFromCharacter(char)
		if plr.Name == script.Parent.Parent.Parent.OwnerName.Value and plr.leaderstats.Money.Value >= price.Value then
			plr.leaderstats.Money.Value = plr.leaderstats.Money.Value - price
			product.Parent = script.Parent.Parent.Parent
		end
	end
end)

and here is the error

14:48:39.733 - Workspace.Tycoon.Purchasing.Purchase - Price.Script:10: attempt to index global 'price' (a number value) 14:48:39.734 - Stack Begin 14:48:39.734 - Script 'Workspace.Tycoon.Purchasing.Purchase - Price.Script', Line 10 14:48:39.734 - Stack End

I have tried to fix this but I have had no luck whatsoever so I will be very thankful to anyone who can help me,

2 comments

0

The Price value needs to be either a NumberValue or an IntValue. Make sure it is not a SringValue.

0

I have made it into a number value but I still get the same error and it was also an IntValue before I changed it to number value.

1 answer

✓ Accepted answer

Price is not an instance that has a Value property.

price = script.Parent.Price.Value

Which is why you can't acces it.

price.Value

Change line 10 to this.

 if plr.Name == script.Parent.Parent.Parent.OwnerName.Value and plr.leaderstats.Money.Value >= price then

1 comment

0

Thank you so much, this worked

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