Hello, I’m making a military game with regiments. But when I team someone to a regiment, it wil not save. Can someone help me, Thank you.
Research saving and datastores.
When you’ve made a script to do this, and it doesn’t work, then we’ll be able to help, but if you haven’t even tried to make something that works, we can’t help.
What do you mean by “it will not save”?
Do you want it so that if someone is on a team and if they leave and rejoin they will be put back to the last team they were in? If that’s your case use a datastore
Yes, if someone leaves he is the same team
Yes, but i don’t know how to script
On playeradded event add a stringvalue, when the player is switching teams the server will write over what team they selected, upon .PlayerRemoving you should save that stringvalue to your datastore. When the player rejoins, check what the stringvalue says and if you have a team that matches the stringvalue, assign that player to the team. I recommend you look at the datastore api reference
I’m sorry, but like i said i don’t know how to script
Then you should be looking at basics of scripting like functions/ Property manipulation/ etc. to get a grasp of what you’re doing. The datastore api reference has examples you can use for your case,
I know the basics, but i don’t know that much
You can’t be expecting to be spoon fed here, he’s given you the gist of what you need to do. You gotta put effort in to make it happen.
i am [i got to something random here or else i cant reply]
Interesting premise, I haven’t written a team-related DataStore script before.
local players = game:GetService("Players")
local teams = game:GetService("Teams")
local dataStores = game:GetService("DataStoreService")
local teamStore = dataStores:GetDataStore("TeamStore")
local function onPlayerAdded(player)
local success, result = pcall(function()
return teamStore:GetAsync("Team_"..player.UserId)
end)
if success then
if result then
local team = teams:FindFirstChild(result)
if team then
player.Team = team
end
end
else
warn(result)
end
end
local function onPlayerRemoving(player)
local team = player.Team
if team then
local success, result = pcall(function()
return teamStore:SetAsync("Team_"..player.UserId, team.Name)
end)
if success then
if result then
return
end
else
warn(result)
end
end
end
local function onServerShutdown()
for _, player in ipairs(players:GetPlayers()) do
local team = player.Team
if team then
local success, result = pcall(function()
return teamStore:SetAsync("Team_"..player.UserId, team.Name)
end)
if success then
if result then
return
end
else
warn(result)
end
end
end
end
players.PlayerAdded:Connect(onPlayerAdded)
players.PlayerRemoving:Connect(onPlayerRemoving)
game:BindToClose(onServerShutdown)
I wouldn’t even bother with ‘-Value’ instances, you can just save/load the player’s team’s name directly instead.
Thank you so much, i was trying to make the script but i wasn’t working.