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

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")

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 ; 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!

4 comments

0

14 & 26. Those parentheses are NOT meant to be there. I am not sure where you learnt to do such a thing.

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:

0

There are a lot of mistakes here. You're moving WAY too fast.

1 answer

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)

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