Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago
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 <eof>, got 'else'

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

1 answer

Log in to vote
1
Answered by 7 years ago

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!

0
It worked! Thanks, man. shootmen -2 — 7y
0
Np BlackOrange3343 2676 — 7y
Ad

Answer this question