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

This script I've created doesn't save, but has no errors. Please help?

Asked by 5 years ago

So, here's the script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DS = game:GetService("DataStoreService"):GetDataStore("Statsandstuff")


game.Players.PlayerAdded:Connect(function(plr)
    local player = plr
    repeat wait() until player.Character

    local hitbox = Instance.new("Part")
    local weld = Instance.new("Weld",hitbox)
    hitbox.Parent = player.Character
    hitbox.Name = "PlayerHitBox"
    hitbox.Size = Vector3.new(3.85, 5.74, 1.19)
    hitbox.Position = Vector3.new(player.Character.UpperTorso.Position.X,player.Character.UpperTorso.Position.Y - 2,player.Character.UpperTorso.Position.Z)
    hitbox.Transparency = 1
    hitbox.CanCollide = false
    weld.Part0 = hitbox
    weld.Part1 = player.Character.HumanoidRootPart

    local folder = Instance.new("Folder")
    folder.Name = player.Name
    folder.Parent = ReplicatedStorage

    local folder2 = Instance.new("Folder")
    folder2.Name = player.Name
    folder2.Parent = game:GetService("ServerScriptService")

    local vars = Instance.new("Folder") 
    vars.Parent = folder
    vars.Name = "Vars"

    local Int = Instance.new("NumberValue")
    Int.Parent = vars
    Int.Name = "Intelligence"

    local Lev = Instance.new("NumberValue")
    Lev.Parent = vars
    Lev.Name = "Level"

    local Points = Instance.new("NumberValue")
    Points.Parent = vars
    Points.Name = "Points"

    local Quirk = Instance.new("StringValue")
    Quirk.Parent = vars
    Quirk.Name = "Quirk"

    local QuirkD = Instance.new("NumberValue")
    QuirkD.Parent = vars
    QuirkD.Name = "QuirkDevelopment"

    local Stam = Instance.new("NumberValue")
    Stam.Parent = vars
    Stam.Name = "Stamina"

    local Str = Instance.new("NumberValue")
    Str.Parent = vars
    Str.Name = "Strength"

    local XP = Instance.new("NumberValue")
    XP.Parent = vars
    XP.Name = "XP"

    local XPTL = Instance.new("NumberValue")    
    XPTL.Parent = vars
    XPTL.Name = "XPtolevel"

    local savedstuff = DS:GetAsync(plr.userId)
    if savedstuff then
        for i,v in pairs(savedstuff) do
            if i % 2 == 0 then
                ReplicatedStorage[plr.Name].Vars:FindFirstChild(savedstuff[i-1]).Value = v
            end
        end

    else
    Int.Value = 1
    Lev.Value = 0
    Points.Value = 0
    Quirk.Value = "Quirkless"
    QuirkD.Value = 1
    Stam.Value = 1
    Str.Value = 1
    XP.Value = 0
    XPTL.Value = 50 
    end

end)

local function savestuff(plr)
    local saveddata = {}
    for i,v in pairs(ReplicatedStorage[plr.Name].Vars:GetChildren()) do
        saveddata[#saveddata + 1] = v.Name
        saveddata[#saveddata + 1] = v.Value 
    end
    DS:SetAsync(plr.userId, saveddata)
end

game.Players.PlayerRemoving:Connect(function(plr)
    savestuff(plr)
end)

I get no errors whatsoever, but it won't save. Please help!

0
Ignore the hitbox stuff, that is irrelevant. AgencyDrone 0 — 5y
0
Player removing must be changed to game:BindToClose because Player removing doesn't work any more for datastores greatneil80 2647 — 5y
0
Possibly on line 7 have wait() until plr.Character.Loaded == true iladoga 129 — 5y
0
So whenever I use BindToClose it stalls the game and nearly crashes studio until saying it didn't work and is either in a queue or stopped the script. AgencyDrone 0 — 5y

Answer this question