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

I'm making a script that can redeem codes that gives in-game items. How do I fix this <eof> error?

local box = script.Parent.Parent:WaitForChild('TextBox')
local button = script.Parent
local code = 'freegun'
local tries = 0
local maxtries = 999999999999999999
button.MouseButton1Click:connect(function()

end)
	
	if box.Text == code then
		button.Text = 'Code accepted'
script.Parent.MouseButton1Click:connect(function() 
end)	
	end
	   
	local tool = script.Parent.Tool:Clone()
	tool.Parent = p.Backpack

        else
		
		button.Text = 'Incorrect password'
		tries = tries + 1
	end
end)

Error: Expected , got 'else'

The error is on 'else', I'm not sure whether I have too many 'ends' or not enough 'ends'.

1 answer

✓ Accepted answer

It actually meant you placed else in the wrong place, you use else in a if statement. For example; If I'm blue then blah blah blah and adding else means if I'm anything other then blue then blah blah blah. You ended your if statement so it didn't work. Try this code I edited;

local box = script.Parent.Parent:WaitForChild('TextBox')
local button = script.Parent
local code = "freegun"
local tries = 0
local maxtries = 99999999
local player = game.Players.LocalPlayer -- I think this is a local script if not then delete this

button.MouseButton1Down:connect(function()
	if box.Text == code then
		wait()
		box.Text = "Code Accepted"
		local tool = script.Parent:WaitForChild("Tool"):Clone()
		tool.Parent = player.Backpack --If top line "player" is deleted then delete this too and change
	else
		wait()
		button.Text = "Incorrect Code"
		tries = tries + 1
	end
end)

If it worked then please accept answer and upvote. If you have any questions then comment below or if you got an error let me know and I will get you back!

2 comments

0

It worked! Thanks, man.

0

Np

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