New Help With An End) Error

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)
	end)        
		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)```
Receiving this error:Error:(33,5)Expected identifier when parsing expression, got ')'
The error might be an extra end or an end needed, but when I tried nothing seemed to work, help would be very appreciated.

You’re missing an end here:
image

1 Like

i think this code has no end : 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


It’s now giving me an expected eof, got end error

delete the end) on 34
30charsssssssssss

1 Like


Now all the values become unknown
and if I add a parenthesis it expected identifier when parsing expression, got ‘)’

because they are unknown,

1 Like

the variables (credits and whatnot) are localised inside the player function, reindentify the varaibles in the serverevent thing

1 Like

So I just copy the code above and paste it below

1 Like


Expected identifier when expression got ‘)’ line 35

thats not a function thing thats a comparator use your brain man just delete the )

2 Likes


in that line, change “= event” to “:Connect(function”


53.4 I changed it already, but the error is now expected end to close function at line 4, but if I add that, it says expected identifier when parsing expression

no, if statements need an end.
@alexthecool600 remove the bracket (line 35)

paste your code here

By the connect function I remove the bracket?

Cause if I do all the values above become unknown

I noticed you did several things wrong , this should work :

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

game.Players.PlayerAdded:Connect(function(player)
    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"
    --Load Datalocal data
	local success , err = pcall(function()
	data = DataStore1:GetAsync(player.UserId)  
  
 end)      
		if  success and 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.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").OnServerInvoke = function(player,NameOfSpaceVehicle)
	local Credits = game.player.leaderstats["Credits"].Value
	local Research = game.player.leaderstats["Research"].Value
	local PlayerUserId = "Player_"..player.UserId
	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 
end
game.Players.PlayerRemoving:Connect(function(player)
    local PlayerUserId = "Player_"..player.UserId
    local data = {}
    for _, v in ipairs(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)

You forgot to close the pcall() with an end)

Also you cannot access local variables defined earlier in blocks of code that have ended, data would be an unknown global if defined locally before , contained in the pcall() statement.

You had to get the datastore like

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

as DataStore itself is not a global.

Pairs is designed to work with dictionaries, ipairs for numerical indices, use the latter in your case.

2 Likes

omg thank you so much!
Also if you are able to help furthermore I have a small issue with a shop, help will be appreciated greatly.

1 Like

No problem, start a new thread so we can help you (as to keep the thread in relation to one topic at a time).