Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can i save the player's team with a datastore? [2]

Asked by 5 years ago
Edited 5 years ago
01local datastore = game:GetService("DataStoreService"):GetDataStore("GameStore")
02 
03game.Players.PlayerAdded:connect(function(player)
04 
05    local team_name = player.Team.Name
06 
07    local team = game.Teams:FindFirstChild(team_name)
08 
09    local key = "user-" .. player.userId
10 
11    local storeditems = datastore:GetAsync(key)
12    if storeditems then
13        team = storeditems[1]
14        print("loaded!")
15        print(team.Name)
View all 29 lines...

ERROR MESSAGE: Cannot store Array in data store. Data stores can only accept valid UTF-8 characters. (At the bottom part) Please fix this, i don't know how to get the player's team (aka team (line 5-7))

0
DataStore2 is easier because it is simplified down. killerbrenden 1537 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

This is how I would do it.

ModuleScript in ServerScriptService and I named it "TeamModule" -

01local teamModule = {}
02 
03local DataStore2 = require(1936396537)
04 
05DataStore2.Combine("MainKey","Team") -- You Can Change MainKey To Any New Value To Reset The DataBase
06 
07local defaultTeam = "None"
08 
09function teamModule:SetPlayerTeam(player)
10    if player:IsA("Player") then
11        local excessData = Instance.new("Folder",player)
12        excessData.Name = "ExcessData"
13 
14        local teamValue = Instance.new("StringValue",excessData)
15        teamValue.Name = "Team"
View all 31 lines...

This is a ServerScript in ServerScriptService and I named it TeamSet -

01local teamModule = require(script.Parent.TeamModule)
02 
03local DataStore2 = require(1936396537)
04 
05local RE = game:GetService("ReplicatedStorage"):WaitForChild("Events")
06 
07game.Players.PlayerAdded:Connect(function(player)
08    teamModule:SetPlayerTeam(player)
09    wait(1)
10    local team = game:GetService("Teams"):FindFirstChild(player.ExcessData.Team.Value).TeamColor
11    wait()
12    player.TeamColor = team
13    wait(0.25)
14    player:LoadCharacter()
15end)
View all 24 lines...

And Then I have a folder in ReplicatedStorage called Events, and you should keep all RemoteEvents and Functions in there, and it will save their team. All you have to do is have the first team enabled Auto-Assignable, and the other teams should not have that enabled. It will get their team, and then respawn them on their team at that spawn. It should work, if it doesn't, let me know so I can tweak it and fix it for you. And for it to work in studio if you want to test it, you have to put a BoolValue inside of ServerStorage and name it SaveInStudio and have it enabled to true for it to work in studio.

Ad

Answer this question