Hi, I am using DataStore2 as a lot of people seem to recommend it. I have set it up, it works fine but I have noticed that when the player dies, it lags then respawns the player 5 seconds later.
Script:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Modules = ReplicatedStorage:WaitForChild("Storage"):WaitForChild("Modules")
local DataStore2 = require(1936396537)
local Settings = require(Modules["Datastores"])
Players.PlayerAdded:Connect(function(plr)
for i,v in pairs(Settings) do
local datastore = DataStore2(i,plr)
local Folder = v.Folder
if v.Folder ~= "Player" then
if plr:findFirstChild(v.Folder) then
Folder = plr[v.Folder]
else
local folder = Instance.new("Folder",plr)
folder.Name = v.Folder
Folder = folder
end
end
if v.Folder == "Player" then
Folder = plr
end
local val = Instance.new(v.ValueType , Folder)
val.Name = i
val.Value = v.Value
if datastore:Get() ~= nil then
val.Value = datastore:Get()
end
val.Changed:connect(function()
datastore:Set(val.Value)
end)
end
end)
Nevermind, I found the cause.
Turns out there was a script in my settings menu that was causing the game to lag, and because I had the datastore script disabled it didnt run.