Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

So I Got This Script From Youtube and it wont work. I’m guessing its outdated?

local DS = game:GetService("DataStoreService"):GetDataStore("Data")

game.Players.PlayerAdded:Connect(function(plr)
	
	local l = Instance.new("Folder")
	l.Name = "leaderstats"
	l.Parent = plr
	
	local v = Instance.new("IntValue")
	v.Name = "Energy"
	v.Parent = l
	
	local file = DS:GetAsync(plr.UserId)
	
	if file then
		v.Value = file[1]
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	DS:GetAsync(plr.UserId,{plr.leaderstats.Points.Value})
end)

13 comments

0

what have you done the fix the script, waht isnt working, did you try in studio or in game?

0

I cant find a error for it. I am also new to scripting

0

did you test in studio?

0

did you test in studio?

0

did you test in studio?

0

did you test in studio?

0

?

0

sorry lag

0

sorry lag

0

sorry lag

0

sorry lag

0

sorry lag

0

sorry lag

1 answer

This is your problem:

At line 21, you are calling :GetAsync() instead of :SetAsync().

here is the fixed script:

local DS = game:GetService("DataStoreService"):GetDataStore("Data")

game.Players.PlayerAdded:Connect(function(plr)

    local l = Instance.new("Folder")
    l.Name = "leaderstats"
    l.Parent = plr

    local v = Instance.new("IntValue")
    v.Name = "Energy"
    v.Parent = l

    local file = DS:GetAsync(plr.UserId)

    if file then
        v.Value = file[1]
    end
end)

game.Players.PlayerRemoving:Connect(function(plr)
    DS:SetAsync(plr.UserId,{plr.leaderstats.Points.Value})
end)

Note that sometimes roblox doesnt really save data is studio, but it does in the actual game.

This discussion is preserved as it was. New answers, comments, and votes are closed.