If your good with datastore

so ive looked at this for like 20 mins and gave up in the output theres no errors so yeah heres my script:

local datastoreservice = game:GetService("DataStoreService")
local StatsData = datastoreservice:GetDataStore("StatsData")

game.Players.PlayerAdded:Connect(function(player)
	local playerId = "Player_"..player.UserId
	local Stats = Instance.new("Folder")
	Stats.Name = "Stats"
	Stats.Parent = player
	
	local Money = Instance.new("IntValue")
	Money.Name = "Money"
	Money.Parent = Stats
	
	local Stamina = Instance.new("IntValue")
	Stamina.Name = "Stamina"
	Stamina.Parent = Stats
	
	local data 
	local success, errormsg = pcall(function()
		data = StatsData:GetAsync(playerId)
	end)
	
	if success then
		if data then
		Money.Value = data.Money
		Stamina.Value = data.Stamina
		end
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	local playerId = "Player_"..player.UserId
	local success, errormsg = pcall(function()
		
		local data = {
			Money = player.Stats.Money.Value;
			Stamina = player.Stats.Stamina.Value;
		}
		
		StatsData:SetAsync(playerId, data)
	end)
	if success then
		print("Data Saved")
	else
		print("Failed to save Data")
		warn(errormsg)
	end
end)
2 Likes

I suggest putting all of it in code blocks with ```, since it is hard to read right now.
Also, if you are testing in studio then turn API services on.

2 Likes

ok i changed it so u can read more easily

2 Likes

If you are testing in studio, have you turned API services on? Any errors at all?

1 Like

the api is turned on this is wat i get in the output

 18:44:07.683  Infinite yield possible on 'ServerScriptService:WaitForChild("Humanoid")'  -  Studio
  18:44:07.683  Stack Begin  -  Studio
  18:44:07.684  Script 'ServerScriptService.PlayerProperties', Line 5  -  Studio  -  PlayerProperties:5
  18:44:07.684  Stack End  -  Studio
  18:44:12.767  Infinite yield possible on 'Workspace.Roastdbacon.Animate:WaitForChild("PlayEmote")'  -  Studio
  18:44:12.767  Stack Begin  -  Studio
  18:44:12.767  Script 'Workspace.Roastdbacon.Animate', Line 729  -  Studio
  18:44:12.767  Stack End  -  Studio
  18:44:12.767  Infinite yield possible on 'Players.Roastdbacon:WaitForChild("stats")'  -  Studio
  18:44:12.767  Stack Begin  -  Studio
  18:44:12.767  Script 'Players.Roastdbacon.PlayerGui.PlayersHud.Stamina.Meter.LocalScript', Line 7  -  Studio
  18:44:12.767  Stack End  -  Studio
  18:44:13.210  Disconnect from ::ffff:127.0.0.1|50846  -  Studio
2 Likes

Any from this script or just from others?

1 Like

pretty sure only this

 18:44:12.767  Infinite yield possible on 'Players.Roastdbacon:WaitForChild("stats")'  -  Studio

is the only thing in output rest is from others

1 Like

Which line did this warning come from? I don’t see a WaitForChild() anywhere in the script.

1 Like
local frame = script.Parent
local character = game:GetService("Players").LocalPlayer.character
local human = character:WaitForChild("Humanoid")
local player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")

local stats = player:WaitForChild("stats")
local Stamina = stats:WaitForChild("Stamina")

local sprinting = false

human.Running:Connect(function(speed)
	if speed >= 19 then
		sprinting = true
	end
end)

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftControl then 
		if sprinting == true then 
			print(Stamina.Value)
		end	
	end
end)

it was coming from this lol

1 Like

Your datastore script looks fine. Check your scripts that change the values. They might not be working and the values never change so you think the datastore script doesn’t work.

1 Like

well the only time i changed it is when i manually went in the game and changed the value in my stats so i dont use any other scripts

Ok that’s the problem. If you’re changing the value in the explorer on the client side, the server doesn’t know the value changed because of FilteringEnabled. Click Test and change to the Server. Then when you change it in the explorer, it can be saved.

1 Like


why cant i access any of these buttons!

1 Like

Click F5 on your keyboard, then click the Test tab.

1 Like

les go it works now!!! am very happy

1 Like