Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Autosave script (stat saving script)?

Asked by 3 years ago

I am making a stat saving script but it just says ServerScriptService.Script:38: Expected ')' (to close '(' at line 34), got 'end' when i test the game... I turned on HTTP and API... Heres the script:

**game.Players.PlayerAdded:connect(function(player)

local StartingMoney = (0)

-------------------------------------------------------- 

local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player

local money = Instance.new("NumberValue")
sticks.Name = "Sticks"
sticks.Parent = leaderstats
sticks.Value = StartingSticks

local dataStore = game:GetService("DataStoreService"):GetDataStore("SticksData")

starterSticks = 0--This is the starter money

game.Players.PlayerAdded:Connect(function(plr)

local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr

local money = Instance.new("IntValue")
sticks.Name = "Sticks" --Put ur currency name here, mine is Money
sticks.Value = dataStore:GetAsync(plr.UserId) or starterSticks
sticks.Parent = leaderstats

end)

game.Players.PlayerRemoving:Connect(function(plr)

dataStore:SetAsync(plr.UserId, plr.leaderstats.Sticks.Value)

end**

2 answers

Log in to vote
0
Answered by 3 years ago

Howdy!

You're missing a parenthesis at the very bottom of your script. Replace your PlayerRemoving function with what I got below.

game.Players.PlayerRemoving:Connect(function(plr)
    dataStore:SetAsync(plr.UserId, plr.leaderstats.Sticks.Value)
end)

You're also missing a "end)" at the end of your PlayerAdded. But before I address that, why do you have a PlayerAdded function INSIDE of a PlayerAdded function? It's a little arbitrary.

I recommend that you just remove the line in the middle of your script that says game.Players.PlayerAdded:Connect(function(plr). It's breaking the script and it's too unnecessary to keep in so there is no reason to fix it. Just remove it.

If this helped you out, consider accepting this answer for those sweet, sweet reputation points. If not, comment below and I (or someone else) will help you out.

Be sure to check out the Roblox API Documentation as well for additional reference.

0
I removed game.Players.PlayerAdded:Connect(function(plr) and tested the game but now it says ServerScriptService.Script:34: Expected 'end' (to close 'function' at line 1), got <eof>; did you forget to close 'function' at line 21? shadow93126 10 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

I removed game.Players.PlayerAdded:Connect(function(plr) but now it says ServerScriptService.Script:34: Expected 'end' (to close 'function' at line 1), got <eof>; did you forget to close 'function' at line 21?

Heres the script:

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

local StartingMoney = (0)

-------------------------------------------------------- 

local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player

local money = Instance.new("NumberValue")
sticks.Name = "Sticks"
sticks.Parent = leaderstats
sticks.Value = StartingSticks

local dataStore = game:GetService("DataStoreService"):GetDataStore("SticksData")

starterSticks = 0--This is the starter money

game.Players.PlayerAdded:Connect(function(plr)

local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr

local money = Instance.new("IntValue")
sticks.Name = "Sticks"
sticks.Value = dataStore:GetAsync(plr.UserId) or starterSticks
sticks.Parent = leaderstats



dataStore:SetAsync(plr.UserId, plr.leaderstats.Sticks.Value)

end)

0
Wait i have a leaderstats script and at same time a autosave script? Do i really need 2 scripts at same time? shadow93126 10 — 3y

Answer this question