The script does not execute for some reason (no errors.)

Hey! I wanted to make a datasaving with two places that loads and saves the boolvalues.
But the script is not working (Script is in the ServerScriptService)

Just really confused why it does not work?!

--// SERVICES
local DataStoreService = game:GetService("DatastoreService")

--// VARS

local ds = DataStoreService:GetDataStore("datatest")
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local RadiopassID = 663864800


local function checkGamePass(player, passID)
	local hasPass = false
	local success, message = pcall(function()
		hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, passID)
	end)
	if not success then
		warn("Error while checking if player has game pass: " .. tostring(message))
		return false
	end
	return hasPass
end

game.Players.PlayerAdded:Connect(function(plr)
	print("executed")
	
	
	local FolderOwned = Instance.new("Folder",plr)
	FolderOwned.Name = "ItemsOwned"

	local RadioOwned = Instance.new("BoolValue",FolderOwned)
	RadioOwned.Name = "RadioOwned"
	----------------------------------------------------

	local FolderEquiped = Instance.new("Folder", plr)
	FolderEquiped.Name = "ItemsEquiped"

	local RadioEquiped = Instance.new("BoolValue",FolderEquiped)
	RadioEquiped.Name = "RadioEquiped"


	local dataofuser = ds:GetAsync(plr.UserId)
	if dataofuser ~= nil then -- anything but nil
		print("Found data for " .. plr.Name)
		RadioOwned.Value = ds[1] 
		--------------------------------
		RadioEquiped.Value = ds[1] 
	else
		print("Replacing no data with new data.")
		
		RadioOwned.Value = false
	
		-------------------------------
		RadioEquiped.Value = false
	end

	if checkGamePass(plr, RadiopassID) then
		-- Player owns the game pass
		print("Player owns the game pass")
	else
		-- Player does not own the game pass
		print("Player does not own the game pass")
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local datasave = {}
	local folderitemsowned = plr:WaitForChild("ItemsOwned")
	local folderitemequiped = plr:WaitForChild("ItemsOwned")
	table.insert(datasave, folderitemsowned:WaitForChild("RadioOwned").Value)
	--------------------------
	table.insert(datasave, folderitemequiped:WaitForChild("RadioEquiped").Value)
	
	local success,response = pcall(function()
		ds:SetAsync(plr.UserId, datasave)
	end)

	if success then
		print("succesfully saved data of " .. plr.Name)
	else
		warn(response)
	end
end)

Are you sure that you have API services enabled in your game’s settings?

1 Like

Yes it is

Is it possible that you made a little mistake here?

Also, try printing the “datasave” table in the PlayerRemoved function and see if it’s empty before you save it. Do the same when you start to retrieve the data.

if you try this code does it execute?

--// SERVICES
local DataStoreService = game:GetService("DatastoreService")

--// VARS

local ds = DataStoreService:GetDataStore("datatest")
local RadiopassID = 663864800


local function checkGamePass(player, passID)
	local hasPass = false
	local success, message = pcall(function()
		hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, passID)
	end)
	if not success then
		warn("Error while checking if player has game pass: " .. tostring(message))
		return false
	end
	return hasPass
end

game.Players.PlayerAdded:Connect(function(plr)
	print("executed")
	
	
	local FolderOwned = Instance.new("Folder",plr)
	FolderOwned.Name = "ItemsOwned"

	local RadioOwned = Instance.new("BoolValue",FolderOwned)
	RadioOwned.Name = "RadioOwned"
	----------------------------------------------------

	local FolderEquiped = Instance.new("Folder", plr)
	FolderEquiped.Name = "ItemsEquiped"

	local RadioEquiped = Instance.new("BoolValue",FolderEquiped)
	RadioEquiped.Name = "RadioEquiped"


	local dataofuser = ds:GetAsync(plr.UserId)
	if dataofuser ~= nil then -- anything but nil
		print("Found data for " .. plr.Name)
		RadioOwned.Value = ds[1] 
		--------------------------------
		RadioEquiped.Value = ds[1] 
	else
		print("Replacing no data with new data.")
		
		RadioOwned.Value = false
	
		-------------------------------
		RadioEquiped.Value = false
	end

	if checkGamePass(plr, RadiopassID) then
		-- Player owns the game pass
		print("Player owns the game pass")
	else
		-- Player does not own the game pass
		print("Player does not own the game pass")
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local datasave = {}
	local folderitemsowned = plr:WaitForChild("ItemsOwned")
	local folderitemequiped = plr:WaitForChild("ItemsOwned")
	table.insert(datasave, folderitemsowned:WaitForChild("RadioOwned").Value)
	--------------------------
	table.insert(datasave, folderitemequiped:WaitForChild("RadioEquiped").Value)
	
	local success,response = pcall(function()
		ds:SetAsync(plr.UserId, datasave)
	end)

	if success then
		print("succesfully saved data of " .. plr.Name)
	else
		warn(response)
	end
end)
1 Like

I am so sorry the error was right on top of the output oh god yea it was writting mistake.

but still thanks for the help :saluting_face:

Oh wow lol well at least you caught it

Mark your post as the solution

yea thanks for trying to help me I was so frustrated

1 Like

It’s the full story of developing, just one mistake and the entire thing breaks

yep. True facts and real I mean everyone does spelling mistakes

Just imagine someone writing thousands apon thousands of lines of machine code. And oops:

- Uh oh! Syntax error!

okay now it’s time to let this topic fade away

1 Like

oh god welp rewriting the code again for the 100th time!

1 Like

Just a question is okay if I can add you on roblox?
for maybe my bigger problems that I have xd

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.