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

Attempts, wrong lines?

Hello there! I'm learning to script, of course I have trouble with this one! :-(

How do you script, If you enter wrong code 3 times then the boolvalue = true,

Is it proper to use this line? repeat until time(3) script.Parent.Parent.Code.Text = "You submitted three wrong code, this building is now lockdown" workspace.Lockdown.BoolValue.Value = true

function codeentry()
    if script.Parent.Parent.Code.Text == "1337" then
        script.Parent.Parent.Code.Text = "Correct" 
wait(2)
    script.Parent.Parent.Parent.Parent.Frame:TweenPosition(UDim2.new(-0.5, 0, 0.25, 0), "Out", "Elastic", 2.5)

    else
if script.Parent.Parent.Code.Text >= "1337" then
       script.Parent.Parent.Code.Text = "Incorrect" 

repeat until time(3)
       script.Parent.Parent.Code.Text = "You submitted three wrong code, this building is now lockdown" 
workspace.NationalAssemblyAlarm.Code2.Value = true
end
end
end

script.Parent.MouseButton1Up:connect(codeentry)

1 answer

✓ Accepted answer

I would rewrite this entirely to resemble something like the following;


local Count = 0	--Idk what the "time" thing was, but its best to set a local interval value.

script.Parent.MouseButton1Up:connect(function ()	--You can embed functions directly into events/connections.
	if script.Parent.Parent.Code.Text ~= "1337" then
		script.Parent.Parent.Code.Text = "Incorrect"
		if not Count >= 3 then	--If the count is not yet at 3, then add 1.
			Count = Count + 1
			if Count == 3 then
				script.Parent.Parent.Code.Text = "3 Invalid Attempts, Lockdown Initiated."	--I shortened that text for convenience.
				workspace.NationalAssemblyAlarm.Code2.Value = true
			end
		end
	else
		script.Parent.Parent.Code.Text = "Correct"
		wait(2)
    		script.Parent.Parent.Parent.Parent.Frame:TweenPosition(UDim2.new(-0.5, 0, 0.25, 0), "Out", "Elastic", 2.5)
	end
end)

Hope that works, if there are any problems, let me know because I typed a little fast... Lol Regards, Xetrax

3 comments

0

Thank you for re-writing, I'm not that kind advanced yet lol. There is a problem within line 6, ---- ERROR >>>> Players.Player1.PlayerGui.DeactiveAlarmGUI.Frame.SecurityNote.Entry.Script:6: attempt to compare boolean with number 10:27:31.037 - Stack Begin 10:27:31.039 - Script 'Players.Player1.PlayerGui.DeactiveAlarmGUI.Frame.SecurityNote.Entry.Script', Line 6 10:27:31.040 - Stack End

0

Never mind, I fixed it, you just need to add ( Count >= 3) heh.

0

Lol, glad you caught the error yourself, and I'm glad it worked. ;)

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