Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is "if" causing issues to the script and underlined red?

Asked by
CodeWon 181
3 years ago
Edited 3 years ago

The word "if" in my script is underlined red and is giving me an error why?

It says theres a problem on line 3.

game.Players.PlayerRemoving:Connect(function(player)

    local success, errormessage = pcall(function()
        myDataStore:SetAsync(player.UserId.."-coins",player.leaderstats.Coins.Value)
    end

    if success then
        print("Data saved")
    else
        print("Error saving data")
        warn(errormessage)
    end

end)

1 answer

Log in to vote
2
Answered by
0hsa 193
3 years ago

You forgot to put the ) at the pcall end:

this;

local success, errormessage = pcall(function()
        myDataStore:SetAsync(player.UserId.."-coins",player.leaderstats.Coins.Value)
end

to:

local success, errormessage = pcall(function()
        myDataStore:SetAsync(player.UserId.."-coins",player.leaderstats.Coins.Value)
end)
Ad

Answer this question