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

My datastore script isn't working and i can't seem to find the problem, help?

local DataStore = game:GetService("DataStoreService"):GetDataStore("LastLogin")


game.Players.PlayerAdded:connect(function(Player)

	local LastLogin = DataStore:GetAsync(Player.userId)
	local leaderstats = player:WaitForChild("leaderstats") -- switched to WFC, will yield

	if LastLogin then

		local Seconds = tick()-LastLogin
		local Minutes = Seconds/60
		local Hours = Minutes/60
		script.Parent.TimeFrame.TextLabel.Text = ("Next Award In: "..Hours.."")

		if Hours >= 24 then

			script.Parent.NotificationFrame.Visible = true

			-- This can be a for loop
			for SoundNum = 1, 7 do
				script.Parent["CointDrop"..SoundNum]:Play()
				wait(.1)
			end
	 		
	 		leaderstats.Coins.Value = leaderstats.Coins.Value +100

   			wait(2)
   			script.Parent.NotificationFrame.Visible = false
			DataStore:SetAsync(Player.userId,tick())

		end

	else

		DataStore:SetAsync(Player.userId,tick())

	end

end)

The output is telling me nothing that could tell me what's wrong with the script. This is a local script inside of a ScreenGui. The screen gui contains 2 frames named NotificationFrame and TimeFrame.

1 answer

✓ Accepted answer

DataStoreService cannot be accessed by a Local Script. Only a Script has access to DataStoreService. This is to help prevent hacking into a games DataStores and changing values.


You need to make the local script only work on the GUI while a Script controls saving data.

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