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

Incomplete statement: expected assignment or a function call obby?

local DataStoreService = game:GetService("DataStoreService")

local myDataStore = DataStoreService:GetDataStore("MyDataStore")
	 
game.Players.PlayerAdded:connect(function(player)
 local leaderstats = Instance.new("Folder")
 leaderstats.Name = "leaderstats"
 leaderstats.Parent= player
 
 local stage = Instance.new("IntValue")
 stage.Name = "Stage"
 stage.Parent leaderstats
 ack2.Value = 0
 
 local data
 local success, errormessage = pcall(function)
	myDataStore:GetAsync(player.UserId.."")
 end)
	
 if success then
	stage.value = data
 else
	print("There was an error whilst getting your data")
	warn(errormessage)
 end
end)

game.Players.PlayerRemoving:Connect(function(player)
	
 local success, errormessage = pcall(function)
	myDataStore:SetAsync(player.UserId.."stage",player.leaderstats.Stage.Value)
	end)
	
	if success then
		print("Player Data successufully saved!")
	else
		print("There was an error when saving data")
		warn(errormessage)
	end
end)
	 
 stage.Value = ds1:GetAsync(plr.UserId) or 1
 ds1:SetAsync(plr.UserId, stage.Value)
	 
 stage.Changed:connect(function()
  ds1:SetAsync(plr.UserId, stage.Value)
 end)
end)

3 comments

0

Give it one last shot, something slipped under my fnigers!

0

no is still not working

0

But thank you for your help!

1 answer

Your program contained syntax errors on lines 16-18. You also had several logic issues with you Script which were going to run you into a cesspool of semantic errors too. Please be careful when writing code.

Note:

It is also highly recommended not to to make :SetAsync() calls every time the ValueObject updates. You put your DataStore at high-risk for exhaustion problems. Since you're saving a single Value, it's not important to do so either, so just leave requests for PlayerLeaving.

You should also use :BindToClose() with DataStore's to compensate for abrupt server-shutdownts.

local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("MyDataStore")

local Players = game:GetService("Players")

Players.PlayerAdded:connect(function(Player)
	local Leaderstats = Instance.new("Folder")
	Leaderstats.Name = "leaderstats"
	Leaderstats.Parent= Player

	local Stage = Instance.new("IntValue")
	Stage.Name = "Stage"
	Stage.Value = 0
	Stage.Parent = leaderstats

	local Data;
	local Success, ErrorMessage = pcall(function()
		Data = myDataStore:GetAsync(Player.UserId.."-Stage")
	end)
	if (Success) then
		Stage.Value = Data
	else
		print("There was an error whilst getting your data!")
		warn(ErrorMessage)
	end
end)

Players.PlayerRemoving:Connect(function(Player)
	local Leaderstats = Player:FindFirstChild("Leaderstats")
	if (Leaderstats and Leaderstats.Stage) then
		local Stage = Leaderstats.Stage.Value
		local Success, ErrorMessage = pcall(function()	
			myDataStore:SetAsync(Player.UserId.."-Stage", Stage)
		end)
		if (Success) then
			print("Successfully saved data!")
		else
			print("There was an error whilst saving your data!")
			warn(ErrorMessage)
		end
	end
end)

game:BindToClose(function()
	for _,Player in pairs(Players:GetPlayers()) do
		Player:Kick() --// Force PlayerLeaving to fire
	end
end)

Remember to accept this answer if it helps!

6 comments

0

Sorry there was problem between lines 37 and 41 There was an error whilst saving your data! I don't know what that could be the problem I would really appreciate your response thank you.

0

It just says nil

0

My apologies, a simple syntax error. The code above should be all dandy!

0

sorry is still says There was an error whilst saving your data nil and Success and ErrorMessage are Underlined

0

Same deal again, give it a shot now!

0

Sorry there are no errors anymore but it wouldn't say successfully saved data and when I am at a checkpoint it would not load there the next time I log out

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