hi, I encounter a problem when trying to Firing a Client, the problem was The FireClient unexpectedly Fired all clients (tried print statement to test). What is the problem of my code?
-- Received LocalScript
-- Remove the leave matchmaking button if timer is running out (The button is deleted for all users once a user joined a match)
invis.OnClientEvent:Connect(function()
print("I got Fired (DELETE_INSTANCE_SCRIPT)")
script.Parent.Visible = false
end)
-- Processed ServerScript
timeout.OnServerEvent:Connect(function(p, t)
local reserveCode = ts:ReserveServer(GameId)
print("Timeout.")
if t == "ab220AEm" then
-- Fire the client so the button will be removed
re2:FireClient(p)
-- Teleportation Processing
local plrToTeleport = {}
for k,v in pairs(rs.a:GetChildren()) do
table.insert(plrToTeleport, game:GetService("Players"):FindFirstChild(v.Value))
end
ts:TeleportToPrivateServer(GameId, reserveCode, plrToTeleport)
table.clear(plrToTeleport)
rs.a:FindFirstChild(tostring(p).."_Joined"):Destroy()
wait(5)
-- normalize after the teleportation is processed
normal:FireAllClients()
else
-- if invalid key given, the player will be kicked
p:Kick("Caught in 4K for exploiting")
end
end)
-- LocalScript Firing the Server
ev.OnClientEvent:Connect(function()
script.Parent.Visible = true
-- Timer
for i = TIME, 0, -1 do
-- In case if user wants to cancel the matchmaking break the timer
if TIME == CANCEL_OFFSET then
break
end
script.Parent.Text = "Game Starting in " .. tostring(i)
wait(1)
end
-- Return The time to 5 seconds if the user cancelled
if TIME == CANCEL_OFFSET then
TIME = 5
return
end
script.Parent.Text = "Teleporting..."
timeout:FireServer("ab220AEm")
end)
