THE ORB
Starting the studio

Duplicate entry '<value>' for key '<index>'

A script tried to save something that already exists — usually a player being added twice.

groupsSaving fails for that playercodeNeeds a developer

Do this first

If it happens on every join, the script is inserting without checking first. Report it to the author.

bug_reportPaste your whole console instead

What it means

An INSERT tried to write a value that a UNIQUE or PRIMARY key already holds. MySQL refused the whole statement. The message names both the value and the index it collided with, which together identify the row.

What causes it

Ordered by how often it is the answer.

  1. 1

    Inserting a player who already exists

    A playerConnecting or first-join handler that inserts unconditionally. Second join, same identifier, collision.

  2. 2

    A handler registered twice

    The same event bound in two files, or a resource restarted without its handler being cleaned up, so every action runs twice.

  3. 3

    A retry after a timeout that actually succeeded

    The first insert worked and the response was lost; the retry collides.

  4. 4

    Two servers on one database

    A dev box and a live box sharing credentials.

  5. 5

    An id generated client-side

    Anything the client supplies as a primary key will eventually repeat.

How to tell which one is yours

Find the row that is already there:

SELECT * FROM users WHERE identifier = 'the-value-from-the-message';

If it looks like a legitimate existing player, the insert should not have run at all. If it is a duplicate of a row created seconds ago, you are inserting twice.

Where to look

The INSERT in the resource, and whether anything checks for existence first.

How to fix it

Say what should happen on a collision rather than letting it error:

-- keep the existing row, do nothing
INSERT IGNORE INTO users (identifier, name) VALUES (?, ?)

-- or update it
INSERT INTO users (identifier, name) VALUES (?, ?)
ON DUPLICATE KEY UPDATE name = VALUES(name)

Still stuck on your own code?

This page is what this error usually means. Paste your console into Server Fixer and it will rank everything in it and tell you what to do first, and if you would rather not touch it, ORBIE can repair the script and hand the resource back ready to drop in.

bug_reportOpen Server Fixer

Errors that travel with this one