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
4 years ago
Edited 4 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.

01game.Players.PlayerRemoving:Connect(function(player)
02 
03    local success, errormessage = pcall(function()
04        myDataStore:SetAsync(player.UserId.."-coins",player.leaderstats.Coins.Value)
05    end
06 
07    if success then
08        print("Data saved")
09    else
10        print("Error saving data")
11        warn(errormessage)
12    end
13 
14end)

1 answer

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

You forgot to put the ) at the pcall end:

this;

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

to:

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

Answer this question