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

can anyone fix the Error: Expected 'end' (to close 'function' at line 8), got 'else' error?

Asked by 2 years ago
local gamepass = 16730719
local market = game:GetService("MarketplaceService")
local replicatedStorage = game:GetService("ReplicatedStorage")

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(Character)
        if market:UserOwnsGamePassAsync(player.UserId, gamepass) then
            replicatedStorage.Remotes.Lift.OnServerEvent:Connect(function(player)
                player.leaderstats.Views.Value = player.leaderstats.Views.Value + 2
        else
            replicatedStorage.Remotes.Lift.OnServerEvent:Connect(function(player)
                player.leaderstats.Views.Value = player.leaderstats.Views.Value + 1
            end
        end)
end
end)
end)

there is actually 2 errors error 1: Error: (10,3) Syntax error: Expected 'end' (to close 'function' at line 8), got 'else'

error 2: Error: (14,3) Syntax error: Expected ')' (to close '(' at line 11), got 'end'

2 answers

Log in to vote
0
Answered by 2 years ago
Edited by JesseSong 2 years ago

Problem: (Re-edited by JesseSong!)

The error means the code expected an end to close on the event of OnServerEvent to enclose the function! You didn't add an end with a parenthesis on line 13, and therefore got the error: Expected ')' (to close '(' at line 11), got 'end'

Solution:

Add the end with an ending parenthesis like this end) on line 13

Fixed Script:

local gamepass = 16730719
local market = game:GetService("MarketplaceService")
local replicatedStorage = game:GetService("ReplicatedStorage")


game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(Character)
        if market:UserOwnsGamePassAsync(player.UserId, gamepass) then
            replicatedStorage.Remotes.Lift.OnServerEvent:Connect(function(player)
                player.leaderstats.Views.Value = player.leaderstats.Views.Value + 2
            end)
        else
            replicatedStorage.Remotes.Lift.OnServerEvent:Connect(function(player)
                player.leaderstats.Views.Value = player.leaderstats.Views.Value + 1
            end)
        end
    end)
end)

Comment below whether you have any more questions and I'll be able to help you!

2
You should include an explenation as to what was causing the error, instead of just giving them their fixed code. deeskaalstickman649 475 — 2y
0
The code is right, but the answer is wrong  @NickyPlayz2011 JesseSong 3916 — 2y
0
The reason @Not_prototype's code  errored is because he didn't add an ending parenthesis on line 13. Also, the function requires an end on line 9, since it's connected to an RBXScriptSignal (OnServerEvent) JesseSong 3916 — 2y
0
uhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh ok NickyPlayz2011 82 — 2y
View all comments (2 more)
0
Re-edited JesseSong 3916 — 2y
0
breh NickyPlayz2011 82 — 2y
Ad
Log in to vote
0
Answered by 2 years ago

I originally thought you had two too many ends, but it seems that you've nested two listeners.

local gamepass = 16730719
local market = game:GetService("MarketplaceService")
local replicatedStorage = game:GetService("ReplicatedStorage")

replicatedStorage.Remotes.Lift.OnServerEvent:Connect(function(player)
    if market:UserOwnsGamePassAsync(player.UserId, gamepass) then
        player.leaderstats.Views.Value = player.leaderstats.Views.Value + 2
    else
        player.leaderstats.Views.Value = player.leaderstats.Views.Value + 1
    end
end)

You don't need the PlayerAdded nor the CharacterAdded event as you already get player from the client when firing a RemoveEvent. I do not think you can nest a listener inside an event either.

0
did u read my comment on the previous answer? JesseSong 3916 — 2y
0
What do you mean? efficacies 180 — 2y
0
i mean, did you read my comment on @NickyPlayz2011's answer? JesseSong 3916 — 2y

Answer this question