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

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

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

✓ Accepted answer

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)

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