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

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

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)

2 comments

0

What exactly does it say is wrong on line 15?

0

Workspace.Tycoon.Purchasing.Product - Price.Script:15: attempt to index global 'plr' (a nil value)

2 answers

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.

2 comments

0

Do the same for line 8. Put parentheses.

0

It still does not work: Workspace.Tycoon.Purchasing.Product - Price.Script:15: attempt to index global 'plr' (a nil value)

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.

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