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

How would i be able to make a DataStore script filtering enable compatible to save player's data?

Asked by
oSyM8V3N 429 Moderation Voter
6 years ago

Ok so i think the reason why its not working is because im only changing your values for the client-side. I think you need to do something like make a remote event but i don't know how to do that with my DataStore/saving script.

Here's the script :

local RemoteEvent = game.ReplicatedStorage['RemoteEvent']
RemoteEvent.OnServerEvent:connect(function(player)
local DSService = game:GetService('DataStoreService'):GetDataStore('DBSRData')
game.Players.PlayerAdded:connect(function(p)
    wait(2.5)
    -- Define variables
    local stats = game.ServerStorage.Data:Clone()
    stats.Parent = p
    local uniquekey = 'id-'..p.userId
    local names = {}

    for i, v in pairs(p.Data:GetChildren()) do
        table.insert(names, v.Name)
    end

    -- GetAsync
    local GetSaved = DSService:GetAsync(uniquekey)
    if GetSaved then
        for i, v in pairs(p.Data:GetChildren()) do
            v.Value = GetSaved[i]
        end

        for i=1, #GetSaved do
                --print(i .. ": " .. names[i] .. " = " .. tostring(GetSaved[i]))
        end
    else
        local NumbersForSaving = {}
            for i, v in pairs(p.Data:GetChildren()) do
                table.insert(NumbersForSaving, v.Value)
            end
        DSService:SetAsync(uniquekey, NumbersForSaving)
    end
end)

game.Players.PlayerRemoving:connect(function(p)
    local uniquekey = 'id-'..p.userId
    local Savetable = {}
        for i, v in pairs(p.Data:GetChildren()) do
            table.insert(Savetable, v.Value)
        end

    DSService:SetAsync(uniquekey, Savetable)            
end)
end)
0
Look on the wiki if you don't know how to use anything, like Remote Events, besides things that are very undescriptivE on the wiki. hiimgoodpack 2009 — 6y

1 answer

Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
6 years ago

This should be a ServerScript in ServerScriptService. You don't need to use RemoteEvents here. However, you will need to use RemoteEvents/Functions if you're changing the players stats Locally.

0
It is in serverscriptservice, can you give me an ex with the remote events/functions? oSyM8V3N 429 — 6y
0
Are you changing the players stats in a LocalScript? Azarth 3141 — 6y
0
Yeah i am, when a player presses E it increases by 15. Do i need to add a remote event for that? oSyM8V3N 429 — 6y
0
Yes. I suggest making a new question with that script. Azarth 3141 — 6y
Ad

Answer this question