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

Why is the "end" underlined?

This script is having an error that says "12:36:41.945 - ServerScriptService.Script:37: Expected ')' (to close '(' at line 28), got 'end'", can someone help me? Here is the script:

game.Players.PlayerAdded:Connect(function(player)
	local folder = Instance.new("Folder",player)
	folder.Name = "leaderstats"
	local currency1 = Instance.new("IntValue", folder)
	currency1.Name = "Cash"
	player.CharacterAdded:Connect(function(character)
		character:WaitForChild("Humanoid").Died:Connect(function()
			local tag = character.Humanoid:FindFirstChild("creator")
			if tag ~= nil then
				if tag.Value ~= nil then
					currency1.Value = currency1.Value + 10
					local data
					local success, errormessage = pcall(function()
						data = CashDataStore:GetAsync(player.UserID.."-cash")
						if success then
							cash.Value = data
						else
								print("There was an error whilst getting your data")
								warn(errormessage)
					end
				end)
			end
		end
	end)
end)

game.Players.PlayerRemoving:Connect(function(player)
	local success, errormessage = pcall(function()
		CashDataStore:SetAsync(player.UserID.."-cash", player.leaderstats.Cash.Value)
		if success then
			print("Player Data successfully saved!")
			else
				print("There was an error when saving data")
				warn(errormessage)
			end
		end
	end)  --This is the line that's underlined in red.
end)

2 comments

0

You only need three ends. Two of them will have the bracket after it, and one will not.

0

I got this error: 12:47:42.859 - ServerScriptService.Script:37: Expected 'end' (to close 'function' at line 1), got

2 answers

✓ Accepted answer
game.Players.PlayerAdded:Connect(function(player)
    local folder = Instance.new("Folder")
    folder.Name = "leaderstats"
    folder.Parent = player

    local currency1 = Instance.new("IntValue")
    currency1.Name = "Cash"
    currency1.Value = 0
    currency1.Parent = folder
    player.CharacterAdded:Connect(function(character)
        character:WaitForChild("Humanoid").Died:Connect(function()
            local tag = character.Humanoid:FindFirstChild("creator")
            if tag ~= nil then
                if tag.Value ~= nil then
                    currency1.Value = currency1.Value + 10
                    local data
                    local success, errormessage = pcall(function()
                        data = CashDataStore:GetAsync(player.UserId.."-cash")
                        if success then
                            cash.Value = data
                        else
                             print("There was an error whilst getting your data")
                                warn(errormessage)
                        end
                    end)
                end
            end
        end)
    end)
end)
game.Players.PlayerRemoving:Connect(function(player)
    local success, errormessage = pcall(function()
        CashDataStore:SetAsync(player.UserID.."-cash", player.leaderstats.Cash.Value)
        if success then
            print("Player Data successfully saved!")
            else
                print("There was an error when saving data")
                warn(errormessage)
            end
    end) 
end)

You don't need an extra end and you missed another end to close the PlayerAdded function. Now this should work! Also, remember to always parent last, it is inefficient to parent first!

4 comments

0

Got this error, like the others who answered too: 13:19:00.136 - ServerScriptService.Script:37: Expected 'end' (to close 'function' at line 1), got

0

Now the "CashDataStore", "success" and the "errormessage are underlined in blue, will this affect the script? I got no errors.

0

Let me fix.

0

The whole script is now fixed.

Hi Abysmallow!

Your script has an extra end that is not needed.

Try this:

game.Players.PlayerAdded:Connect(function(player)
    local folder = Instance.new("Folder",player)
    folder.Name = "leaderstats"
    local currency1 = Instance.new("IntValue", folder)
    currency1.Name = "Cash"
    player.CharacterAdded:Connect(function(character)
        character:WaitForChild("Humanoid").Died:Connect(function()
            local tag = character.Humanoid:FindFirstChild("creator")
            if tag ~= nil then
                if tag.Value ~= nil then
                    currency1.Value = currency1.Value + 10
                    local data
                    local success, errormessage = pcall(function()
                        data = CashDataStore:GetAsync(player.UserID.."-cash")
                        if success then
                            cash.Value = data
                        else
                                print("There was an error whilst getting your data")
                                warn(errormessage)
                    end
                end)
            end
        end
    end)
end)

game.Players.PlayerRemoving:Connect(function(player)
    local success, errormessage = pcall(function()
        CashDataStore:SetAsync(player.UserID.."-cash", player.leaderstats.Cash.Value)
        if success then
            print("Player Data successfully saved!")
        else
            print("There was an error when saving data")
            warn(errormessage)
        end
    end)  --This is the line that's underlined in red.
end)

Hope I helped!

2 comments

0

Got this error, like the others who tried to answer: 13:19:00.136 - ServerScriptService.Script:37: Expected 'end' (to close 'function' at line 1), got

0

False. It will not work, the ends need to be swapped

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