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

Why won't the "if" statement on line 16 work?

functions to gradually increase/decrease transparency of a textlabel:

function appear(label)
    print("appear function called")
    for i = 1, 0, -.1 do
        label.TextTransparency = i
        label.TextStrokeTransparency = i
        wait()
    end
end 


function disappear(label)
    print("disappear function called")
    for i = 0, 1, .1 do
        label.TextTransparency = i
        label.TextStrokeTransparency = i
        wait()
    end
end 

main script:

db = 0
visible = false
playerOwnsOrange = false
script.Parent.MainFrame.AppearanceF.ColorF.Orange.MouseButton1Click:Connect(function()
	local price = 2000
	local lp = game.Players.LocalPlayer
	local cash = lp:findFirstChild("leaderstats").Cash
	local bank = lp:findFirstChild("leaderstats").Bank
	if playerOwnsOrange == true then --if player already bought this
		print("PlayerOwnsOrange; money not deducted")
		CarThatTouched.Body.CarBody.CarColor.Color = Color3.fromRGB(235, 131, 39)
		script.Parent.MainFrame.AppearanceF.ColorF.Color.Text = "Color: Orange"
	elseif cash.Value >= price and playerOwnsOrange == false then
		cash.Value = cash.Value - price --deducts money
		playerOwnsOrange = true
		if db == 0 then --(everything works up until here) makes textlabel appear using functions defined above
			print("test") -- NOT PRINTED
			db = 1
			local plrgui = lp:findFirstChild("PlayerGui")
			local mc = plrgui.ChangeOfMoney.MoneyChangeFrame.MoneyChange
			if visible == false then
				mc.Text = "-$"..price
				appear(mc)
				visible = true
				print("CoM visible")
				wait(4)
				disappear(mc)
				visible = false
				db = 0
			elseif visible == true then
				print("com visible")
				disappear(mc)
				db = 0
			end
		end
		CarThatTouched.Body.CarBody.CarColor.Color = Color3.fromRGB(235, 131, 39)
		script.Parent.MainFrame.AppearanceF.ColorF.Color.Text = "Color: Orange"
		script.Parent.MainFrame.AppearanceF.ColorF.Orange.Text = ""

there are "end"s, just later in the script

6 comments

0

Try 'if db < 1 then'

0

Or just simply use Bools.

0

Same result

0

Try changing the variable from db = 0 to local db = 0

0

Local variables are used so the variable is only used in a certain function that it can only be seen from that function. Putting local on db would do noting since it would just means that it can be used in the whole script which is the same regardless without 'local'.

0

The "if" function won't work if the "elseif" is false?

1 answer

db = 0
visible = false
playerOwnsOrange = false
script.Parent.MainFrame.AppearanceF.ColorF.Orange.MouseButton1Click:Connect(function()
    local price = 2000
    local lp = game.Players.LocalPlayer
    local cash = lp:findFirstChild("leaderstats").Cash
    local bank = lp:findFirstChild("leaderstats").Bank
    if playerOwnsOrange == true then --if player already bought this
        print("PlayerOwnsOrange; money not deducted")
        CarThatTouched.Body.CarBody.CarColor.Color = Color3.fromRGB(235, 131, 39)
        script.Parent.MainFrame.AppearanceF.ColorF.Color.Text = "Color: Orange"
    elseif cash.Value >= price and playerOwnsOrange == false then
        cash.Value = cash.Value - price --deducts money
        playerOwnsOrange = true
print(db)
        if db == 0 then --(everything works up until here) makes textlabel appear using functions defined above
            print("test") -- NOT PRINTED
            db = 1
            local plrgui = lp:findFirstChild("PlayerGui")
            local mc = plrgui.ChangeOfMoney.MoneyChangeFrame.MoneyChange
            if visible == false then
                mc.Text = "-$"..price
                appear(mc)
                visible = true
                print("CoM visible")
                wait(4)
                disappear(mc)
                visible = false
                db = 0
            elseif visible == true then
                print("com visible")
                disappear(mc)
                db = 0
            end
        end
        CarThatTouched.Body.CarBody.CarColor.Color = Color3.fromRGB(235, 131, 39)
        script.Parent.MainFrame.AppearanceF.ColorF.Color.Text = "Color: Orange"
        script.Parent.MainFrame.AppearanceF.ColorF.Orange.Text = ""

So, I dont see anything wrong. I put a print function to print Db. What does it output?

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