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

My script is not working well could I get some advice on how to fix it?

Asked by 9 years ago

Here is my script. Output says there is something wrong with line 15. It is a tycoon script inside one of those buttons you purchase items with.

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.Name=script.Parent.ProductName.Value.."-"..price
if price==0 then
    script.Parent.Name=script.Parent.ProductName.Value.." - Free"
end

script.Parent.Head.Touched:connect(function(hit)
    chr=hit.Parent
    if chr:findFirstChild("Humanoid") and game.Players:GetPlayerFromCharacter(chr) then
        if plr.Name==script.Parent.Parent.Parent.OwnerName.Value and plr.leaderstats.Money.Value>=price then
            plr.leaderstats.Money.Value=plr.leaderstats.Money.Value-price
            product.Parent=script.Parent.Parent.Parent
            script.Parent:remove()
        end
    end
end)
0
What exactly does it say is wrong on line 15? adark 5487 — 9y
0
Workspace.Tycoon.Purchasing.Product - Price.Script:15: attempt to index global 'plr' (a nil value) frostmario2 30 — 9y

2 answers

Log in to vote
0
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
9 years ago

Try replacing it with this:

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

Parentheses indicates you're comparing it to a number.

0
Do the same for line 8. Put parentheses. Shawnyg 4330 — 9y
0
It still does not work: Workspace.Tycoon.Purchasing.Product - Price.Script:15: attempt to index global 'plr' (a nil value) frostmario2 30 — 9y
Ad
Log in to vote
0
Answered by
Relatch 550 Moderation Voter
9 years ago

You did not define plr. Try using something like this.

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
plr = game.Players:GetChildren()

script.Parent.Name=script.Parent.ProductName.Value.."-"..price
if price==0 then
    script.Parent.Name=script.Parent.ProductName.Value.." - Free"
end

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

As you used to define product and price.

Answer this question