Hello! When I was creating a datastore I was wondering if pcall() can be and is used anywhere else outside of datastores?
Yes you can! pcall is commonly used when making HTTP requests and many other things.
As far as I know, yes. Cause they can filter out errors without making the script stop.
I use pcall for very important things so it doesn’t error. Like Datastores. Giving them points and stuff like that!
Yes, you can use pcalls to detect if a function is successfull or errors. Here’s an example.
local Success, Func = pcall(function()
print(game.Players.LocalPlayer.Character.Name)
end)
if Success then
print("Works.")
end
those things mentioned above, yes, but some people also just use pcall() for their entire script to make a user-friendly Error System that prints errors in more easy-to-understand way.
that is an awful idea. first off it adds extra code for no reason and also decreases performance
yes, if your too lazy to script weather the player can be teleported
if not pcall(function()
player.Character.HumanoidRootPart.CFrame = game.Workspace.Platform.Position + Vector3.new(0,1.5,0)
end) then
print("Teleport failed!")
end
There’s several different issues you have to catch if you had just used
player.Character.HumanoidRootPart.CFrame = game.Workspace.Platform.Position + Vector3.new(0,1.5,0)
- The player’s character is nil
- The player’s HumanoidRootPart’s missing (if they fell into the void)
- The platform’s missing
Well this is just bad programming habit if anything.
pcall is just preventing errors from output,
pcall will return true if the code doesn’t make any errors
pcall will return false if the code does make any errors
local success, message = pcall(function()
nil:Destroy() --will not print any error
end)
and preventing the script from stopping
I know some people who do. I don’t.