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

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

Asked by 7 years ago

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,

0
The Price value needs to be either a NumberValue or an IntValue. Make sure it is not a SringValue. FiredDusk 1466 — 7y
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. Cheesepotato999 8 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

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
0
Thank you so much, this worked Cheesepotato999 8 — 7y
Ad

Answer this question