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

Expected end near EOF?

Asked by 8 years ago

23:18:53.481 - Players.Player.Backpack.Tool.LocalScript:84: 'end' expected (to close 'function' at line 28) near '<eof>'


--[[Scripted by WolfgangVonPrinz]]-- --[[ Thank you for using my gun kit! It's very much appreciated, this kit is a work in progress, but while it will never be as large as Turbo's, it'll be a more solid design, that will loke a lot better. --]] --[[SETTINGS]]-- damage = 30 -- Set this to how much damage you want the gun to do RPM = 600 -- How many rounds a minute can the gun fire? ammo = 10 -- How much ammo in a clip do you want? ammostore = 100 -- How many stored rounds do you want? --[[SETTINGS/]]-- local tool = script.Parent local user local firingrate = 60 / RPM local canfire = true auto = false tool.Equipped:connect(function(mouse) user = tool.Parent if script.Parent:FindFirstChild("ammo") == false then print("There ain't no ammo vals! better make 'ne") local a = Instance.new("NumberValue", script.Parent) a.Name = "ammo" a.Value = ammo local b = Instance.new("NumberValue", script.Parent) b.Name = "storedammo" b.Value = ammostore mouse.Button1Down:connect(function() auto = true while auto == true do if canfire == false then return end canfire = false if ammo > 0 then ammo = ammo - 1 -- Mah first ray evar local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit*300) local hit, position = game.Workspace:FindPartOnRay(ray, user) print(hit) -- This is used for debugging local hitted = hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") if hitted then hitted:TakeDamage(damage) wait(firingrate) canfire = true else print("Outta ammo broski") end mouse.Button1Up:connect(function() print("Button is up") auto = false end) end end end ) end

3 answers

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
8 years ago

Tab your code correctly

Your code is jumbled up. The left edge of the code should cleanly show how things are grouped.

An then or a function or do starts a block, and an end or until stops a block.

When you start a block, the indentation should increase by exactly one tab.

Your error, "expected end near EOF" means Lua expected an end (because you had started something), but didn't find it, near "EOF", meaning "end of file". This would be obvious if you applied proper tabbing style!

Here is what your code looks like when it is tabbed correctly:

--[[Scripted by WolfgangVonPrinz]]--

--[[ Thank you for using my gun kit!
It's very much appreciated, this kit is a work in progress, but while it will never be
as large as Turbo's, it'll be a more solid design, that will loke a lot better.
--]]

--[[SETTINGS]]--

damage = 30 -- Set this to how much damage you want the gun to do

RPM = 600 -- How many rounds a minute can the gun fire?
ammo = 10 -- How much ammo in a clip do you want?
ammostore = 100 -- How many stored rounds do you want?

--[[SETTINGS/]]--

local tool = script.Parent
local user

local firingrate = 60 / RPM
local canfire = true
auto = false

tool.Equipped:connect(function(mouse)
    user = tool.Parent
    if script.Parent:FindFirstChild("ammo") == false then
        print("There ain't no ammo vals! better make 'ne")
        local a = Instance.new("NumberValue", script.Parent)
        a.Name = "ammo"
        a.Value = ammo
        local b = Instance.new("NumberValue", script.Parent)
        b.Name = "storedammo"
        b.Value = ammostore
        mouse.Button1Down:connect(function()
            auto = true
            while auto == true do
                if canfire == false then
                    return
                end
                canfire = false
                if ammo > 0 then
                    ammo = ammo - 1

                    -- Mah first ray evar
                    local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p -  tool.Handle.CFrame.p).unit*300)
                    local hit, position = game.Workspace:FindPartOnRay(ray, user)
                    print(hit) -- This is used for debugging
                    local hitted = hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid")

                    if hitted then
                        hitted:TakeDamage(damage)

                        wait(firingrate)
                        canfire = true
                    else 
                        print("Outta ammo broski")
                    end

                    mouse.Button1Up:connect(function()
                        print("Button is up")
                        auto = false
                    end)
                end
            end
        end)
    end

Notice how the last line is "floating"? That means something was started, but never ended. You can find out what by just scanning up vertically.

This is the culprit: tool.Equipped:connect(function(mouse).

You have to end the function, and close ) the paren.

Your code should be ending like this:

                    mouse.Button1Up:connect(function()
                        print("Button is up")
                        auto = false
                    end)
                end
            end
        end)
    end
end)

Cleanup

You can clean a few things up. For instance, the Button1Up connection doesn't belong as a part of the Button1Down connection. They are separate things. You shouldn't reconnect the Button1Up event over and over.

== true or == false are not idiomatic. Just use while auto do and if not canfire then

Define things where they're used. There's no reason to define local user outside of the only function that it's used in.

Ad
Log in to vote
0
Answered by 8 years ago

'end' expected (to close 'function' at line 28) near '<eof>' Means you didn't add an end where it belongs. Here, this should work.

--[[Scripted by WolfgangVonPrinz]]--

--[[ Thank you for using my gun kit!
    It's very much appreciated, this kit is a work in progress, but while it will never be
    as large as Turbo's, it'll be a more solid design, that will loke a lot better.
--]]

--[[SETTINGS]]--

damage = 30 -- Set this to how much damage you want the gun to do



RPM = 600 -- How many rounds a minute can the gun fire?
ammo = 10 -- How much ammo in a clip do you want?
ammostore = 100 -- How many stored rounds do you want?

--[[SETTINGS/]]--


local tool = script.Parent
local user

local firingrate = 60 / RPM
local canfire = true
auto = false

tool.Equipped:connect(function(mouse)
user = tool.Parent
if script.Parent:FindFirstChild("ammo") == false then
print("There ain't no ammo vals! better make 'ne")

    local a = Instance.new("NumberValue", script.Parent)
    a.Name = "ammo"
    a.Value = ammo
    local b = Instance.new("NumberValue", script.Parent)
    b.Name = "storedammo"
    b.Value = ammostore
    mouse.Button1Down:connect(function()
        auto = true
        while auto == true do
        if canfire == false then return end
        canfire = false
        if ammo > 0 then
            ammo = ammo - 1

        -- Mah first ray evar
        local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p -  tool.Handle.CFrame.p).unit*300)
        local hit, position = game.Workspace:FindPartOnRay(ray, user)
        print(hit) -- This is used for debugging
        local hitted = hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid")

        if hitted then
            hitted:TakeDamage(damage)



        wait(firingrate)
        canfire = true
        else 
            print("Outta ammo broski")

        end







    mouse.Button1Up:connect(function()
        print("Button is up")
        auto = false
end)

    end
        end
    end


)
end
end)

0
Doesn't error, but it doesn't work, either. :( WolfgangVonPrinz 0 — 8y
Log in to vote
0
Answered by 8 years ago

You forgot an end for line 28. You had the ")" correct but you forgot the end that goes with the function.

--[[Scripted by WolfgangVonPrinz]]--

--[[ Thank you for using my gun kit!
    It's very much appreciated, this kit is a work in progress, but while it will never be
    as large as Turbo's, it'll be a more solid design, that will loke a lot better.
--]]

--[[SETTINGS]]--

damage = 30 -- Set this to how much damage you want the gun to do



RPM = 600 -- How many rounds a minute can the gun fire?
ammo = 10 -- How much ammo in a clip do you want?
ammostore = 100 -- How many stored rounds do you want?

--[[SETTINGS/]]--


local tool = script.Parent
local user

local firingrate = 60 / RPM
local canfire = true
auto = false

tool.Equipped:connect(function(mouse)
user = tool.Parent
if script.Parent:FindFirstChild("ammo") == false then
print("There ain't no ammo vals! better make 'ne")

    local a = Instance.new("NumberValue", script.Parent)
    a.Name = "ammo"
    a.Value = ammo
    local b = Instance.new("NumberValue", script.Parent)
    b.Name = "storedammo"
    b.Value = ammostore
    mouse.Button1Down:connect(function()
        auto = true
        while auto == true do
        if canfire == false then return end
        canfire = false
        if ammo > 0 then
            ammo = ammo - 1

        -- Mah first ray evar
        local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p -  tool.Handle.CFrame.p).unit*300)
        local hit, position = game.Workspace:FindPartOnRay(ray, user)
        print(hit) -- This is used for debugging
        local hitted = hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid")

        if hitted then
            hitted:TakeDamage(damage)



        wait(firingrate)
        canfire = true
        else 
            print("Outta ammo broski")

        end







    mouse.Button1Up:connect(function()
        print("Button is up")
        auto = false
end)

    end
        end
    end

end
end)


Answer this question