My script:
local DataStoreService = game:GetService("DataStoreService") local milesDataStore = DataStoreService:GetDataStore("milesDataStore") game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new ("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local Miles = Instance.new("IntValue") Miles.Name = "Miles" Miles.Parent = leaderstats while true do() wait (120) Miles = Miles + 100 local UserId = player.UserId --Loading the Miles in game 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 local miles = player.leaderstats.Miles.Value 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!
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 function OnPlayerAdded(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local Miles = Instance.new("IntValue") Miles.Name = "Miles" Miles.Parent = leaderstats while wait(5) do Miles.Value += 100 end end game.Players.PlayerAdded:Connect(OnPlayerAdded) game.Players.PlayerRemoving:Connect(function(player) milesDataStore:SetAsync(player.UserId, player.leaderstats.Miles.Value) end)