Ad
Log in to vote
0

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

Asked by 16 days ago

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!

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

1 answer

Log in to vote
0
Answered by 15 days ago

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

Answer this question