0

# How do you fix this error when making a datastore when trying to make a leaderstat?

My script:

local DataStoreService = game:GetService("DataStoreService")
local milesDataStore = DataStoreService:GetDataStore("milesDataStore")

local Miles = Instance.new("IntValue")
Miles.Name = "Miles"

while true do()
wait (120)
Miles = Miles + 100

local UserId = player.UserId

local miles

local success, errormessage = pcall(function()
miles = milesDataStore:GetAsync(UserId)
end)

if success then
Miles.Value = miles
end
end)

game.Players.PlayerRemoving:Connect(function(player)
local UserId = player.UserId

milesDataStore:SetAsync(UserId, miles)
end)



My error: Syntax Error: (14, 16) Expected identifier when parsing expression, got’)' Syntax Error: (14, 15) Incomplete statement: expected assignment or a function call Syntax Error: (31, 5) Expected identifier when parsing expression, got')' Syntax Error: (38, 34) Expected 'end' (to close "function' at line 4), got <eof>; did you forget to close 'function' at line 34?

I don’t understand what messed up and how to fix it; any help would be great!

0
14 & 26. Those parentheses are NOT meant to be there. I am not sure where you learnt to do such a thing. Ziffixture 6863 — 15d
0
You don't seem to have a grasp on scope, either. It's a fundamental subject in computer programming, so I recommend you read up: Ziffixture 6863 — 15d
0
There are a lot of mistakes here. You're moving WAY too fast. Ziffixture 6863 — 15d

0

This code is completely wrong! Learn lua first, and after move to roblox lua. You dont even know how to use loops, man, you rush it too fast!

local DataStoreService = game:GetService("DataStoreService")
local milesDataStore = DataStoreService:GetDataStore("milesDataStore")

local Miles = Instance.new("IntValue")
Miles.Name = "Miles"

while wait(5) do
Miles.Value += 100
end
end