Saving Data to a Server rather than a player?

So I was wondering if it was possible to save data to a server rather then a player. For example in my game i’m making I wanna have 2 sides. Heros and Villains, say if a Villain robbed a bank a value would go up for villains controlling the city. However if a Hero saved that bank from being robbed it go up for Heros controlling the city and it’d be a constant battle to keep the city safe. Essentially I need help with task since Data stores is my weak point in scripting.

4 Likes

Yes, there is a way, but Roblox has DataStore limitations, so this is probably not the best way to do it.

local dataStore = game:GetService("DataStoreService")
local serverData = dataStore:GetDataStore("ServerData")

function addpoint(team,amount)
	local getData = serverData:GetAsync(team)
	if getData then
			serverData:SetAsync(team,getData+amount)
	else
					serverData:SetAsync(team,amount)

	end
end
2 Likes

Ok, thanks you think it’d be fine if it was a game that was only aimed at like at most 300 players? because the game might be group locked

1 Like

Use a remote event to send it to the server,
Use DataStoreService and set the key to something like

playersUserIdHere .. ValuesName

Then set and get the values as you need when the remote event gets updated and every so often do an autosave and save it when players leave the game.

Storage wise to temporarily keep there values in the server, make a folder in Serverstorage with some intvalues and remove them when the player leaves the game.

Here is a good tutorial by GetEnveloped on the DevForum:

I wish you luck, datastore shouldn’t be to hard once you get the hang of it. :smile:

3 Likes

Thanks for the help!

2 Likes