DataStore Setup (CRITICAL!)
DataStore is how votes are saved. Without it, votes disappear when the server restarts.
⚠️ If you skip this section, all votes will be lost.
What is DataStore?
DataStore is Roblox's database. It saves player data (in this case, votes) so they persist across server restarts.
Without DataStore:
- Server restarts → all votes gone
- Players lose their votes
- Election resets
With DataStore:
- Server restarts → votes are still there
- Players rejoin → their vote is loaded
- Election data survives
Step 1: Enable Studio DataStore Access
This is the most important step. You must do this in the place where you're testing.
For Place File Users
- Open your
.rbxlplace file in Roblox Studio - Click Home tab
- Find Game Settings button (looks like a gear/settings icon)
- In the left panel, click Security
- Scroll down and find these two toggles:
- Enable Studio Access to API Services → Turn ON (green)
- Enable DataStore Access in Studio → Turn ON (green)
- Click Save or close the panel
Visual Guide:
Home Tab → Game Settings (gear icon)
↓
Left Panel → Security
↓
Find "Enable Studio Access to API Services" → Toggle ON
Find "Enable DataStore Access in Studio" → Toggle ON
⚠️ If you don't do this:
- You'll see errors like "DataStore access denied"
- Votes won't save
- Testing won't work properly
For Published Games
If you've published this to your actual game:
- Go to https://www.roblox.com/games
- Find your game
- Click ⋯ (three dots) → Configure Game
- Go to Security in left panel
- Enable "Enable API Services" if not already on
- DataStore is automatically enabled for published games
Optional: HTTP requests for Discord webhooks
If you use Settings.discord to notify an admin Discord channel, the server must be allowed to call outbound HTTP (Home → Game Settings → Security → Allow HTTP Requests → ON). This is independent of DataStore but uses the same Security panel. Full setup: Settings — Discord webhook.
Optional: Studio plugin for data visualization
To inspect or visualize stored data while testing (for example vote profiles or related keys), this Creator Store plugin is a good fit: asset 701506235. More context: Recommended Studio tooling.
Step 2: Test That DataStore Works
After enabling, test it:
- Open your place in Studio
- Click Play
- Look at the Output panel (at bottom of Studio)
- Check for these messages:
Good Signs ✓
[ElectionSystem] Initialized
[DataStore] Profile loaded for player 12345
Bad Signs ✗
DataStore access denied
Failed to load profile
HTTP 403: Forbidden
If you see bad signs, go back to Step 1 and make sure both toggles are ON.
Step 3: Verify Votes Save
Test that votes actually persist:
- Start the game (click Play)
- Vote for someone (use your custom UI or the built-in booth)
- Check Output for:
VOTE recorded ok user=Player1 - Stop the game (click Stop)
- Start again (click Play)
- Check the Output for:
[DataStore] Profile loaded - 1 vote found
If you see the second message, DataStore is working! Your vote persisted across restarts.
Understanding Vote Persistence
When DataStore works correctly, here's what happens:
Player Joins
Player connects
↓
ElectionManager loads player's DataStore profile
↓
Profile contains: { userId: "123", ballot: [...], timestamp: 1234567890 }
↓
Vote is restored to in-memory Store
↓
Player can see they already voted (button disabled)
Player Votes
Player clicks "Vote for Alice"
↓
Server records vote in memory (Store)
↓
Server saves to DataStore immediately
↓
If server restarts → vote is still there
Troubleshooting
Error: "DataStore access denied" or "HTTP 403"
Solution:
- Check that both toggles in Game Settings → Security are ON
- Make sure you're in the correct place file
- Try closing Studio completely and reopening it
- If it still fails, check your Roblox account permissions
Error: "Failed to load profile"
Solution:
- This usually means ProfileService can't find the DataStore
- Make sure you enabled both API Services toggles
- Wait a few seconds and test again (DataStore initialization takes time)
Votes disappear on restart
Solution:
- DataStore likely isn't enabled
- Go back to Step 1
- Make sure both toggles are ON (not just one)
How do I know if DataStore is actually saving?
Look in the Output panel while playing:
DataStore saving vote:
VOTE recorded ok user=Player1 uid=123456789
DataStore persisting vote on rejoin:
[DataStore] Profile loaded - vote found for user Player1
If you see these messages, you're good!
For Published Games (After You Publish)
Once you publish your game to Roblox:
- DataStore is automatically enabled for published games
- Votes automatically persist
- No special setup needed
Just make sure in the game settings (roblox.com/games) that API Services is enabled (it usually is).
Advanced: Clearing DataStore (for Testing)
If you need to reset all votes for a fresh test:
⚠️ Warning: This deletes all stored votes permanently!
- In Roblox Studio, go to View → Server Script Activity
- Click Command Bar
- Type this (warning: this clears everything!):
(Replace
game:GetService("DataStoreService"):GetDataStore("ElectionPlayerData"):RemoveAsync("Player_123")123with the player's user ID)
Better way: Use the admin command in-game:
/cleardata [username]
Summary Checklist
Before testing elections:
- Opened place file in Roblox Studio
- Clicked Home → Game Settings
- Clicked Security in left panel
- Toggled ON: "Enable Studio Access to API Services"
- Toggled ON: "Enable DataStore Access in Studio"
- Saved settings
- Clicked Play to test
- Checked Output for "Profile loaded" message
- Cast a test vote
- Stopped and restarted game
- Verified vote persisted (shows in Output)
If all checkboxes are done, DataStore is working correctly!
Next Steps: