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

"(" expected to (close "("at line 20) near <eof> HOW TO FIX??

local DataStore =
 game:GetService("DataStoreService"):GetDataStore("StoreName")
	 
	game.Players.PlayerAdded:connect(function(player)
	 local key = "key-"..(player.userId)
	 local folder = Instance.new("Folder",player)
	 folder.Name = "leaderstats"
	 local currency1 = Instance.new("IntValue",folder)
	 currency1.Name = "Money"
	 
	 local save = DataStore:GetAsync(key)
	 if save then
	  currency1.Value = save[1]
	 else
	  local load = {currency1.Value}
	  DataStore:SetAsync(key,load)
	 end
end)
	 
	game.Players.PlayerRemoving:connect(function(player)
	 local key = "key-"..(player.userId)
	 local Folder = player:WaitForChild("leaderstats")
	 local load = {leaderstats:FindFirstChild("Money").Value}
	DataStore:SetAsync(key,load)
end

FORGIVE ME IF I AM ASKING MANY QUESTIONS :( I AM NEW IN THIS SCRIPTING WORLD I AM ORIGINALLY FROM THE BUILDING WORLD BUT I WANTED TO DO A NEW THING BUT I NEED SOME ADVICE FROM THE SCRIPTING WORLD AND ALSO THIS SCRIPT IS FOR DATA SAVING IF YOU CAN ANSWER THIS PLEASE SAY IF THIS IS A DATA SAVING SCRIPT CAUSE I HAVE BUILT A BANK BUT THE PLAYERS MONEY WON'T SAVE IF THEY QUIT. ALSO IF THERE'S A NY MORE PROMBLEMS PLEASE FIX THEM :(.

this is my project btw: https://www.roblox.com/games/2259153311/AY3
i think its good.

1 comment

0

( was expected to close "(" at line 20 near (end of file/end of script/whatever). How simple was that error?

2 answers

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

    game.Players.PlayerAdded:connect(function(player)
     local key = "key-"..(player.userId)
     local folder = Instance.new("Folder",player)
     folder.Name = "leaderstats"
     local currency1 = Instance.new("IntValue",folder)
     currency1.Name = "Money"

     local save = DataStore:GetAsync(key)
     if save then
      currency1.Value = save[1]
     else
      local load = {currency1.Value}
      DataStore:SetAsync(key,load)
     end
end)

    game.Players.PlayerRemoving:connect(function(player)
     local key = "key-"..(player.userId)
     local Folder = player:WaitForChild("leaderstats")
     local load = {leaderstats:FindFirstChild("Money").Value}
    DataStore:SetAsync(key,load)
end)

Have fun.

There is no reason to accept this answer.

1 comment

0

And also, do not use free scripts without the knowledge of what they do.

Here is the fixed script:

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

    game.Players.PlayerAdded:connect(function(player)
     local key = "key-"..(player.userId)
     local folder = Instance.new("Folder",player)
     folder.Name = "leaderstats"
     local currency1 = Instance.new("IntValue",folder)
     currency1.Name = "Money"

     local save = DataStore:GetAsync(key)
     if save then
      currency1.Value = save[1]
     else
      local load = {currency1.Value}
      DataStore:SetAsync(key,load)
     end
end)

    game.Players.PlayerRemoving:connect(function(player)
     local key = "key-"..(player.userId)
     local Folder = player:WaitForChild("leaderstats")
     local load = {leaderstats:FindFirstChild("Money").Value}
    DataStore:SetAsync(key,load)
end)

Thanks for accepting answer

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