Script end) syntax error, need help

Need help with this script, it says there’s an error with the end) at the moment, I really don’t know how to fix it.

        script.Parent.ClickDetector.MouseClick:Connect(function(PlayerWhoClicked)
	local MarketPlaceService = game:GetService("MarketplaceService")
	local Coins = PlayerWhoClicked.leaderstats.Scamollars
	local GamepassID = 19552415 -- REPLACE 1234567 WITH YOUR GAMEPASS ID
	local sound = game.Workspace.ERROR

	game.Players.PlayerAdded:Connect(function(player)
		if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserID, GamepassID) then
			Coins.Value = Coins.Value + 2
			sound:Play()
		else
			Coins.Value = Coins.Value + 1
			sound:Play()
end
		end)

IF YOU CAN, HERES THE DOWNLOAD TO THE GAME, MAKE SURE TO PUBLISH IT AND ABLE API, IF YOU FIX IT, PLEASE SEND BACK THE FIXED VERSION

devforumsupport.rbxl (42.8 KB)

You need to add an ‘end’ to close the ‘if’ statement.

script.Parent.ClickDetector.MouseClick:Connect(function(PlayerWhoClicked)
    local MarketPlaceService = game:GetService("MarketplaceService")
    local Coins = PlayerWhoClicked.leaderstats.Scamollars
    local GamepassID = 19552415
    local sound = game.Workspace.ERROR

    game.Players.PlayerAdded:Connect(function(player)
        if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserID, GamepassID) then --- checks if they own the gamepass, if they do...
            player.leaderstats.Scamollars.Value = player.leaderstats.Scamollars.Value + 2 -- if  they have the gamepass, they will receive 2 coins per click
            sound:Play() -- plays music after click
        else
            player.leaderstats.Scamollars.Value = player.leaderstats.Scamollars.Value + 1 -- else if they dont have the gamepass, they will be rewarded 1 coin per click
            sound:Play()
        end
        end) --- the error that i cant fix
2 Likes

Hey, sorry - I sent the wrong code which was faulty, I’ve updated the post.
Received this error from the code

You forgot an end) regarding the event on line 1.
Try this :

script.Parent.ClickDetector.MouseClick:Connect(function(PlayerWhoClicked)
	local MarketPlaceService = game:GetService("MarketplaceService")
	local Coins = PlayerWhoClicked.leaderstats.Scamollars
	local GamepassID = 19552415 -- REPLACE 1234567 WITH YOUR GAMEPASS ID
	local sound = game.Workspace.ERROR


game.Players.PlayerAdded:Connect(function(player)
		if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserID, GamepassID) then
			Coins.Value = Coins.Value + 2
			sound:Play()
		else
			Coins.Value = Coins.Value + 1
			sound:Play()
end
		end)
end)
1 Like

Thanks for the reply, yes but then it causes this:

I edited the message, try the newer one.

Strange, there’s no errors now - but it now does nothing.

If anything, this was the original script, if it may help:

script.Parent.ClickDetector.MouseClick:Connect(function(PlayerWhoClicked)
	local sound = game.Workspace.ERROR

	sound:Play()
	
	local Coins = PlayerWhoClicked.leaderstats.Scamollars
	Coins.Value = Coins.Value + 1
end)

(yes, it worked)

Always track your indentation, respect their usage for readability:

script.Parent.ClickDetector.MouseClick:Connect(function(PlayerWhoClicked)
	local MarketplaceService = game:GetService("MarketplaceService")
	local Coins = PlayerWhoClicked.leaderstats.Scamollars
	local GamepassID = 19552415 -- REPLACE 1234567 WITH YOUR GAMEPASS ID
	local sound = game.Workspace.ERROR

	game.Players.PlayerAdded:Connect(function(player)
		if MarketplaceService:UserOwnsGamePassAsync(player.UserID, GamepassID) then
			Coins.Value = Coins.Value + 2
			sound:Play()
		else
			Coins.Value = Coins.Value + 1
			sound:Play()
		end
	end)
end)

Now as you can see, you kept creating connections on game.Players. That was not necessary and you could have done it differently. To maintain its functionality, you don’t need Players in this case.

script.Parent.ClickDetector.MouseClick:Connect(function(player)
	local MarketplaceService = game:GetService("MarketplaceService")
	local Coins = player.leaderstats.Scamollars
	local GamepassID = 19552415 -- REPLACE 1234567 WITH YOUR GAMEPASS ID
	local sound = game.Workspace.ERROR

	if MarketplaceService:UserOwnsGamePassAsync(player.UserID, GamepassID) then
		Coins.Value = Coins.Value + 2
		sound:Play()
	else
		Coins.Value = Coins.Value + 1
		sound:Play()
	end
end)
2 Likes

I got what’s wrong with the code.
Put playeradded event out of clicked event.
Set variables again.

1 Like

Try this:

        script.Parent.ClickDetector.MouseClick:Connect(function(PlayerWhoClicked)
	local MarketPlaceService = game:GetService("MarketplaceService")
	local Coins = PlayerWhoClicked.leaderstats.Scamollars
	local GamepassID = 19552415 -- REPLACE 1234567 WITH YOUR GAMEPASS ID
	local sound = game.Workspace.ERROR

	game.Players.PlayerAdded:Connect(function(player)
		if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserID, GamepassID) then
			Coins.Value = Coins.Value + 2
			sound:Play()
		else
			Coins.Value = Coins.Value + 1
			sound:Play()
        end
		end)
1 Like

This is the final result.

script.Parent.ClickDetector.MouseClick:Connect(function(PlayerWhoClicked)
	local MarketPlaceService = game:GetService("MarketplaceService")
	local Coins = PlayerWhoClicked.leaderstats.Scamollars
	local GamepassID = 19552415 -- REPLACE 1234567 WITH YOUR GAMEPASS ID
	local sound = game.Workspace.ERROR

end)

game.Players.PlayerAdded:Connect(function(player)
		local Coins = player.leaderstats.Scamollars
                 local sound = game.Workspace.ERROR
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserID, GamepassID) then
                
			Coins.Value = Coins.Value + 2
			sound:Play()
		else
			Coins.Value = Coins.Value + 1
			sound:Play()
end
		end)
1 Like

I updated the post above, which fix the last issue. The Players.PlayerAdded event was not necessary in this case, because the script depends on a ClickDetector which a player clicks. They already exist, and the provided argument from the event should be utilized to its maximum extent.

1 Like
script.Parent.ClickDetector.MouseClick:Connect(function(PlayerWhoClicked)
	local MarketPlaceService = game:GetService("MarketplaceService")
	local Coins = PlayerWhoClicked.leaderstats.Scamollars
	local GamepassID = 19552415 -- REPLACE 1234567 WITH YOUR GAMEPASS ID
	local sound = game.Workspace.ERROR

	game.Players.PlayerAdded:Connect(function(player)
		if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserID, GamepassID) then
			Coins.Value = Coins.Value + 2
			sound:Play()
		else
			Coins.Value = Coins.Value + 1
			sound:Play()
        end
    end)
end)
1 Like

Seems to be unresponsive, not sure why

Hey, it’s also unresponsive, whilst no errors

There are a few possibilities:

  • Your script is a LocalScript. Apparent from how you handle the sounds to be played.
  • Script doesn’t work for some other technical issues.
  • You missed the other script:
script.Parent.ClickDetector.MouseClick:Connect(function(player)
	local MarketplaceService = game:GetService("MarketplaceService")
	local Coins = player.leaderstats.Scamollars
	local GamepassID = 19552415 -- REPLACE 1234567 WITH YOUR GAMEPASS ID
	local sound = game.Workspace.ERROR

	if MarketplaceService:UserOwnsGamePassAsync(player.UserID, GamepassID) then
		Coins.Value = Coins.Value + 2
		sound:Play()
	else
		Coins.Value = Coins.Value + 1
		sound:Play()
	end
end)

  • Other reasons, probably very unlikely.

What kind of script it is and where is the script?

it’s a server script, inside a part