repeat wait() until script.Parent.Product.Value~=nil local product=script.Parent.Product.Value:clone() script.Parent.Product.Value:remove() local price=script.Parent.Price.Value script.Parent.Head.Touched:connect (function(hit) chr=hit.Parent if chr:findFirstChild("Humanoid") and game.Players:GetPlayerFromCharacter(chr) then plr=game.Players:GetPlayerFromCharacter(chr) 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)
I receive the error "Workspace.Tycoon.Purchasing.Product - Price.Script:11: attempt to index upvalue 'price' (a number value)" when I try to test the script and I'm not entirely sure how to fix it as I'm working on learning lua, and I haven't entirely found an answer on google.
Thanks!
repeat wait() until script.Parent.Product.Value ~= nil local product = script.Parent.Product.Value:clone() script.Parent.Product.Value:Destroy() -- remove is depricated, use destroy local price = script.Parent.Price.Value script.Parent.Head.Touched:connect (function(hit) chr = hit.Parent if chr:findFirstChild("Humanoid") and game.Players:GetPlayerFromCharacter(chr) then plr = game.Players:GetPlayerFromCharacter(chr) if plr.Name == script.Parent.Parent.Parent.OwnerName and -- you tried to check if a numbervalue is nil, it doesn't work like that. 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)