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

Script not taking away from a value?

I'm trying to make an "Attempts" script, where you only have 5 attempts, but the script won't subtract the value.

local UName = script.Parent:WaitForChild("UName")
-------------------------------------
local UPass = script.Parent:WaitForChild("UPass")
-------------------------------------
local Attempts = script.Parent:WaitForChild("Attempts").Value
-------------------------------------
local Button = script.Parent:WaitForChild("Login")
-------------------------------------
local pass = {
	["Herro"] = true;
}
-------------------------------------
local transparency = 0
-------------------------------------
local debounce = false
-------------------------------------
local countdown = 10
-------------------------------------
local warning = "You have "..Attempts.." attempts left."
----------------------
local function checkAttempts()
	if Attempts == 0 then
		--Randomness
	else
		Attempts = Attempts - 1 --Here
		script.Parent.Warning.Text = warning
		wait(3)
		script.Parent.Warning.Text = ""
		debounce = false
	end
end
-------------------------------------
Button.MouseButton1Click:connect(function()
	if debounce == false then
		debounce = true
		if pass[UPass.Text] then
			--Randomness 
		else
			checkAttempts()
		end
	end
end)

It will display the text, just not subtract the value. Any suggestions, because there aren't any errors.

Info:

--No filtering Enabled
--It's a local script.

2 comments

0

Try assigning "Attempts" to the Attempts object itself instead of the value, then use Attempts.Value whenever you wish to refer to it through your script. Let me know if that works and I will provide more details afterwards

0

You are using the value of attempts and but not setting them remove the "value" part at the top and change line 25 to Attempts.Value = Attempts.Value -1 so that it updates

1 answer

✓ Accepted answer

Its a simple yet common mistake, on line 05, all you need to do is take away the ".Value" part and re-assign this to where you next use the variable. This is because when you assigned the variable you also assigned the value which means that you cant change it, where as now you can access the child of it:

--(All errors should be fixed)
local UName = script.Parent:WaitForChild("UName")
-------------------------------------
local UPass = script.Parent:WaitForChild("UPass")
-------------------------------------
local Attempts = script.Parent:WaitForChild("Attempts")
-------------------------------------
local Button = script.Parent:WaitForChild("Login")
-------------------------------------
local pass = {
    ["Herro"] = true;
}
-------------------------------------
local transparency = 0
-------------------------------------
local debounce = false
-------------------------------------
local countdown = 10
-------------------------------------
local warning = "You have "..Attempts.Value.." attempts left."
----------------------
local function checkAttempts()
    if Attempts.Value  == 0 then
        --Randomness
    else
        Attempts.Value  = Attempts.Value  - 1 
        script.Parent.Warning.Text = warning
        wait(3)
        script.Parent.Warning.Text = ""
        debounce = false
    end
end
-------------------------------------
Button.MouseButton1Click:connect(function()
    if debounce == false then
        debounce = true
        if pass[UPass.Text] then
            --Randomness 
        else
            checkAttempts()
        end
    end
end)


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