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

Data saving hat is not saving correctly?

Asked by 3 years ago

So I wrote this script with the help of dev forum but the thing is the data saving the hat isn't working. I dont know why it isn't saving the hat that i put on.

local dss = game:GetService("DataStoreService")
local myDataStore = dss:GetDataStore("Outfit")

local function onPlayerLeave(plr)
  local Wear = {} 
  for _,item in pairs(plr.Items) do
    table.insert(Wear,item.Name)
    end
pcall(function()
    myDataStore:SetAsync(plr.UserId,Wear) 
end)
end

local function onPlayerAdded(plr)
    local data 
    local Folder = Instance.new("Folder",plr) 
    pcall(function()
        data = myDataStore:GetAysnc(plr.UserId) 
    end)
    for _,item in pairs(data) do 
        local Value = Instance.new("StringValue",Folder)
        Value.Name = item
    end
    plr.CharacterAdded:Connect(function()
        for i,accessory in pairs(Folder) do
            game.ServerStorage.Everything[accessory.name]:Clone().Parent = plr.Character
        end
    end)    
end

1 answer

Log in to vote
1
Answered by 3 years ago

Ah yes. The classic function shenanigan. replace these lines with the code im giving you

game.Players.PlayerRemoving:Connect(function(plr) -- line 4
end) --line 12
game.Players.PlayerAdded:Connect(function(plr) -- line 14
end) -- line 29

The reason your code didn't work is because you designated the functions, but did not say when they would occur.

These changes would have them occur when a player leaves/joins the game.

If you need further assistance, reach out to me @BlobMaster#8156 or message me on roblox.

You could also try to read this: https://developer.roblox.com/en-us/api-reference/event/Players/PlayerRemoving

0
oh alright Fxding_cam 60 — 3y
Ad

Answer this question