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

why is my data store script not working when I'm pretty sure everything is right?

I have followed tutorials and did everything they told me to do but the script won't work and there is nothing in the output. the only thing I changed is that there isn't a leaderstats folder but it just has a different name.

here is the script

local DataStoreService = game:GetService("DataStoreService")

local DataStore = DataStoreService:GetDataStore("DataStore")

local GravelCo = DataStoreService:GetDataStore("GravelCo")

game.Players.PlayerAdded:Connect(function(player)
	local Data = Instance.new("Folder")
	Data.Name = "DataFolder"
	Data.Parent = player
	
	local GravelColor = Instance.new("IntValue")
	GravelColor.Name = "GravelColor"
	GravelColor.Parent = Data
	
	local data
	local success, error = pcall(function()
		data = GravelCo:GetAsync(player.UserId.."-GravelColor")
	end)
	
	if success then
		GravelColor.Value = data
	else
		warn(error)
		print("error saving")
	end
	
end)

game.Players.PlayerRemoving:Connect(function(player)
	
	local success, error = pcall(function()
		GravelCo:SetAsync(player.UserId.."-GravelColor",player.DataFolder.GravelColor.Value)
	end)
	
	if success then
		print("data Saved")
	else
		print("error Saving")
		warn(error)
	end
	
end)

1 comment

0

try uploading the game and then playing it, they dont work in studio

1 answer

✓ Accepted answer

You don't have to do userid-GravelColor, you can just use the id. Not forcing you to change it but just a reminder.

Also, It might be because your 'error' in pcalls are already a function inside lua. To fix this maybe try doing _error.

Plus, it's an intvalue, not a color/string value. Are you sure you're doing colors by numbers? Have a little debug, see if you can get a result.

game.Players.yasquerda.DataFolder.GravelColor.Value = 1 leave game rejoin game print(game.Players.yasquerda.DataFolder.GravelColor.Value)

Use dev console for this (press F9 and switch to server tab on output). Btw you can't run datastores in studio.

1 comment

0

Yea, it works. You're probably just assigning strings.

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