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

It says eof expected near end. what does this mean?

function onTouched(part)
    name = script.Parent.Name
        local h = part.Parent:FindFirstChild("Humanoid")
    if h ~= nil then
        char = h.Parent
        player = char:GetPlayerFromCharacter(char)
            if player ~= nil then
                leaderstats = player.FindFirstChild("leaderstats")
                if leaderstats ~= nil then
                    stage = leaderstats:FindFirstChild("Stage")
                    if stage ~= nil then
                        stage.Value = name
                    end
                end
            end
        end
    end
end

script.Parent.Touched:connect(onTouched) -- Links event to function

7 comments

0

It means the script is expecting the end of the function usally it means you need to add a closed bracket to your end

0

I've tried

0

@terence404 Examples please?

0

There's an extra end there

0

When I remove an end it still doesn't work.??

0

You're trying to call a function that isn't there on line 6

0

End of file (script) was expected near an end. Indenting saves errors.

3 answers

function onTouched(part)
    name = script.Parent.Name
        local h = part.Parent:FindFirstChild("Humanoid")
    if h ~= nil then
        char = h.Parent
        player = game:GetService("Players"):FindFirstChild(char.Name)
            if player ~= nil then
                leaderstats = player.FindFirstChild("leaderstats")
                if leaderstats ~= nil then
                    stage = leaderstats:FindFirstChild("Stage")
                    if stage ~= nil then
                        stage.Value = name
                    end
                end
            end
    end
end
-- Whatever will be touched has to be here
SpawnLocation = script.Parent -- Make sure it's the right object
SpawnLocation.Touched:Connect(onTouched)

5 comments

0

@DeathGunner132 still doesnt work.

0

It didnt log teh SpawnLocation1 error. I stepped on the spawn it doesnt add. I think the variables arent properly set?

0

Now it says GetPlayerFromCharacter is not a valid member of model

0

Edited

0

Should work now

You put an extra end and you're trying to call a function that isn't there on line 6

function onTouched(part)
    name = script.Parent.Name
        local h = part.Parent:FindFirstChild("Humanoid")
    if h ~= nil then
        char = h.Parent
        player = char:GetPlayerFromCharacter(char) -- HERE <<<<<<<<<<<<<<<<<<<<<
            if player ~= nil then
                leaderstats = player.FindFirstChild("leaderstats")
                if leaderstats ~= nil then
                    stage = leaderstats:FindFirstChild("Stage")
                    if stage ~= nil then
                        stage.Value = name
                    end
                end
            end
        end
    end
end -- HERE <<<<<<<<<<<<<<<<<<<<<

script.Parent.Touched:connect(onTouched) -- Links event to function

you can fix this by changing the code like so:

function onTouched(part)
    name = script.Parent.Name
        local h = part.Parent:FindFirstChild("Humanoid")
    if h ~= nil then
        char = h.Parent
        player = game:GetService("Players"):FindFirstChild(char.Name)
            if player ~= nil then
                leaderstats = player.FindFirstChild("leaderstats")
                if leaderstats ~= nil then
                    stage = leaderstats:FindFirstChild("Stage")
                    if stage ~= nil then
                        stage.Value = name
                    end
                end
            end
        end
    end

p.s. put the script into the checkpoint and make sure to name the part the stage number

###Your code. It’s unnecessarily long. Looks like something straight out of YouTube. Your error was on line 6 as others said, and you added an extra end. This is shortened code.

local plrs = game:GetService"Players"

function onTouch(part)
    local plr = plrs:GetPlayerFromCharacter(part.Parent)
    
    if plr then --You don’t need the ~= nil part, it’s redundant and does nothing
        local leaderstats = plr.leaderstats
        local stage = leaderstats.Stage
        stage.Value = script.Parent.Name
    end
end

script.Parent.Touched:Connect(onTouch) --Connect not connect

On a side note, switch to Connect, as ROBLOX may remove connect soon.

2 comments

0

Nice no errors but Can you edit it so it can add +1 to the leaderstat

0

@incapaz

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