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
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
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)
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)
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)
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)
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.
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)
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)