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

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

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

✓ Accepted answer

##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!

6 comments

2

You should include an explenation as to what was causing the error, instead of just giving them their fixed code.

0

The code is right, but the answer is wrong  @NickyPlayz2011

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)

0

uhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh ok

0

Re-edited

0

breh

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.

3 comments

0

did u read my comment on the previous answer?

0

What do you mean?

0

i mean, did you read my comment on @NickyPlayz2011's answer?

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