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 3 years ago
01local gamepass = 16730719
02local market = game:GetService("MarketplaceService")
03local replicatedStorage = game:GetService("ReplicatedStorage")
04 
05game.Players.PlayerAdded:Connect(function(player)
06    player.CharacterAdded:Connect(function(Character)
07        if market:UserOwnsGamePassAsync(player.UserId, gamepass) then
08            replicatedStorage.Remotes.Lift.OnServerEvent:Connect(function(player)
09                player.leaderstats.Views.Value = player.leaderstats.Views.Value + 2
10        else
11            replicatedStorage.Remotes.Lift.OnServerEvent:Connect(function(player)
12                player.leaderstats.Views.Value = player.leaderstats.Views.Value + 1
13            end
14        end)
15end
16end)
17end)

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 3 years ago
Edited by JesseSong 3 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:

01local gamepass = 16730719
02local market = game:GetService("MarketplaceService")
03local replicatedStorage = game:GetService("ReplicatedStorage")
04 
05 
06game.Players.PlayerAdded:Connect(function(player)
07    player.CharacterAdded:Connect(function(Character)
08        if market:UserOwnsGamePassAsync(player.UserId, gamepass) then
09            replicatedStorage.Remotes.Lift.OnServerEvent:Connect(function(player)
10                player.leaderstats.Views.Value = player.leaderstats.Views.Value + 2
11            end)
12        else
13            replicatedStorage.Remotes.Lift.OnServerEvent:Connect(function(player)
14                player.leaderstats.Views.Value = player.leaderstats.Views.Value + 1
15            end)
16        end
17    end)
18end)

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 — 3y
0
The code is right, but the answer is wrong  @NickyPlayz2011 JesseSong 3916 — 3y
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 — 3y
0
uhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh ok NickyPlayz2011 82 — 3y
View all comments (2 more)
0
Re-edited JesseSong 3916 — 3y
0
breh NickyPlayz2011 82 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

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

01local gamepass = 16730719
02local market = game:GetService("MarketplaceService")
03local replicatedStorage = game:GetService("ReplicatedStorage")
04 
05replicatedStorage.Remotes.Lift.OnServerEvent:Connect(function(player)
06    if market:UserOwnsGamePassAsync(player.UserId, gamepass) then
07        player.leaderstats.Views.Value = player.leaderstats.Views.Value + 2
08    else
09        player.leaderstats.Views.Value = player.leaderstats.Views.Value + 1
10    end
11end)

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 — 3y
0
What do you mean? efficacies 180 — 3y
0
i mean, did you read my comment on @NickyPlayz2011's answer? JesseSong 3916 — 3y

Answer this question