Hello, I am getting a error when trying to fire a client.
Script:
local event = game.ReplicatedStorage:FindFirstChild("TeamChange")
local TeamName = 'Civ'
local Players = game:GetService("Players")
script.Parent.MouseButton1Click:Connect(function(plr)
local susces = game.ReplicatedStorage.TeamChange:InvokeServer(TeamName)
local player = game.Players.LocalPlayer
if susces ~= true then
event:FireClient(game.Players[player],"Team Change Error","There is max players on that team! Please try again later!")
else
event:FireClient(game.Players[player],"Team Change","You are now on the team you chose!")
end
end)
The erroring bit
event:FireClient(game.Players[player],"Team Change Error","There is max players on that team! Please try again later!")
local event = game.ReplicatedStorage:FindFirstChild("TeamChange")
local TeamName = 'Civ'
local Players = game:GetService("Players")
script.Parent.MouseButton1Click:Connect(function(plr)
local _success, _error = pcall(function()game.ReplicatedStorage.TeamChange:InvokeServer(TeamName)end)
local player = game.Players.LocalPlayer
if _error then
event:FireClient(game.Players[player],"Team Change Error","There is max players on that team! Please try again later!")
else
event:FireClient(game.Players[player],"Team Change","You are now on the team you chose!")
end
end)
Even better, just use this instead of going through a redundant step:
if susces ~= true then
event:FireClient(player,"Team Change Error","There is max players on that team! Please try again later!")
else
event:FireClient(player,"Team Change","You are now on the team you chose!")
end