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

Receiving an error for a data store/leader stats?

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

game.Players.PlayerAdded:Connect(function(player)
    local PlayerUserId = "Player_"..player.UserId
    local leaderstats = Instance.new("Folder", player)
    leaderstats.Name = "leaderstats"
    local Credits = Instance.new("IntValue", leaderstats)
    Credits.Name = "Credits"
    local Research = Instance.new("IntValue", leaderstats)
    Research.Name = "Research"
end)
    --Load Data
game.ReplicatedStorage:WaitForChild("CheckPrice").OnServerInvoke = function(player,NameOfSpaceVehicle) --- The script.script.Name
	return game.ServerStorage.SpaceVehicles:FindFirstChild(NameOfSpaceVehicle).Price.Value ---Price located in the vehicle
end
game.ReplicatedStorage:WaitForChild("SpawnSpaceVehicle").OnServerEvent = event(player,NameOfSpaceVehicle)
    local SpaceVehicle = game.ServerStorage.SpaceVehicles:FindFirstChild(NameOfSpaceVehicle):Clone()
    SpaceVehicle:SetPrimaryCFrame(Vector3.new(-183.5,1,-126.5))
    SpaceVehicle.Parent=workspace
    SpaceVehicle:MakeJoints()
    SpaceVehicle.Name = player.UserId.."'s "+NameOfSpaceVehicle
    
    local data
    local success, errormessage = pcall(function()
end)
        data = DataStore1:GetAsync(PlayerUserId)
        if data ~= nil and success then
            Credits.Value = data[1]
            Research.Value = data[2]
        elseif data == nil and success then
            Credits.Value = 500
            Research.Value = 10
	end)
game.Players.PlayerRemoving:Connect(function(player)
    local PlayerUserId = "Player_"..player.UserId
    local data = {}
    for i, v in pairs(player.leaderstats:GetChildren())do
        table.insert(data, v.Value)
    end
    local success, errormessage = pcall(function()
        DataStore1:SetAsync(PlayerUserId,data)        
    end)

    if success then
        print("Data Successfully Saved")

    else
        print("There was an error saving data")
        warn(errormessage)

    end
end)

Error:(34,5)Expected identifier when parsing expression, got ')'

4 comments

0

Make an end and put a closing bracket like this end)

0

The error is now expected on line 35

0

I updated the code above

0

Take away the parenthesis/bracket after "end" on line 34.

2 answers

I think you put the ')' on line 35 instead of 34? Try this and see if it works.

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

game.Players.PlayerAdded:Connect(function(player)
    local PlayerUserId = "Player_"..player.UserId
    local leaderstats = Instance.new("Folder", player)
    leaderstats.Name = "leaderstats"
    local Credits = Instance.new("IntValue", leaderstats)
    Credits.Name = "Credits"
    local Research = Instance.new("IntValue", leaderstats)
    Research.Name = "Research"
end)
    --Load Data
game.ReplicatedStorage:WaitForChild("CheckPrice").OnServerInvoke = function(player,NameOfSpaceVehicle) --- The script.script.Name
    return game.ServerStorage.SpaceVehicles:FindFirstChild(NameOfSpaceVehicle).Price.Value ---Price located in the vehicle
end
game.ReplicatedStorage:WaitForChild("SpawnSpaceVehicle").OnServerEvent = event(player,NameOfSpaceVehicle)
    local SpaceVehicle = game.ServerStorage.SpaceVehicles:FindFirstChild(NameOfSpaceVehicle):Clone()
    SpaceVehicle:SetPrimaryCFrame(Vector3.new(-183.5,1,-126.5))
    SpaceVehicle.Parent=workspace
    SpaceVehicle:MakeJoints()
    SpaceVehicle.Name = player.UserId.."'s "+NameOfSpaceVehicle

    local data
    local success, errormessage = pcall(function()
        data = DataStore1:GetAsync(PlayerUserId)
        if data ~= nil and success then
            Credits.Value = data[1]
            Research.Value = data[2]
        elseif data == nil and success then
            Credits.Value = 500
            Research.Value = 10
        end
    end)
end
game.Players.PlayerRemoving:Connect(function(player)
    local PlayerUserId = "Player_"..player.UserId
    local data = {}
    for i, v in pairs(player.leaderstats:GetChildren())do
        table.insert(data, v.Value)
    end
    local success, errormessage = pcall(function()
        DataStore1:SetAsync(PlayerUserId,data)        
    end)

    if success then
        print("Data Successfully Saved")

    else
        print("There was an error saving data")
        warn(errormessage)

    end
end)

1 comment

0

35,1 expected got end

@srimmbow too many ends, try this.

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

game.Players.PlayerAdded:Connect(function(player)
    local PlayerUserId = "Player_"..player.UserId
    local leaderstats = Instance.new("Folder", player)
    leaderstats.Name = "leaderstats"
    local Credits = Instance.new("IntValue", leaderstats)
    Credits.Name = "Credits"
    local Research = Instance.new("IntValue", leaderstats)
    Research.Name = "Research"
end)
    --Load Data
game.ReplicatedStorage:WaitForChild("CheckPrice").OnServerInvoke = function(player,NameOfSpaceVehicle) --- The script.script.Name
    return game.ServerStorage.SpaceVehicles:FindFirstChild(NameOfSpaceVehicle).Price.Value ---Price located in the vehicle
end
game.ReplicatedStorage:WaitForChild("SpawnSpaceVehicle").OnServerEvent = event(player,NameOfSpaceVehicle)
    local SpaceVehicle = game.ServerStorage.SpaceVehicles:FindFirstChild(NameOfSpaceVehicle):Clone()
    SpaceVehicle:SetPrimaryCFrame(Vector3.new(-183.5,1,-126.5))
    SpaceVehicle.Parent=workspace
    SpaceVehicle:MakeJoints()
    SpaceVehicle.Name = player.UserId.."'s "+NameOfSpaceVehicle

    local data
    local success, errormessage = pcall(function()
        data = DataStore1:GetAsync(PlayerUserId)
        if data ~= nil and success then
            Credits.Value = data[1]
            Research.Value = data[2]
        elseif data == nil and success then
            Credits.Value = 500
            Research.Value = 10
        end
    end)

game.Players.PlayerRemoving:Connect(function(player)
    local PlayerUserId = "Player_"..player.UserId
    local data = {}
    for i, v in pairs(player.leaderstats:GetChildren())do
        table.insert(data, v.Value)
    end
    local success, errormessage = pcall(function()
        DataStore1:SetAsync(PlayerUserId,data)        
    end)

    if success then
        print("Data Successfully Saved")

    else
        print("There was an error saving data")
        warn(errormessage)

    end
end)

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