I’m having a issue where this event is not firing if I put it inside a function, but if I run it at the beginning of the script it works perfectly fine. The code of the function is also running everything but firing the event.
The function gets fired later down the script
local function onKickButtonClicked()
if selectedPlayerId ~= nil then
local playerToKick = game.Players:GetPlayerByUserId(selectedPlayerId)
if playerToKick then
remote:FireServer((game.Players.LocalPlayer.Name .. " kicked " .. tostring(playerToKick)),
(kickReason.Text), game.Players.LocalPlayer.Name)
playerToKick:Kick(game.Players.LocalPlayer.Name .. " kicked you because "..
kickReason.Text)
print("Kicked " .. selectedPlayerId)
else
warn("Could not find player to kick.")
end
else
warn("No player selected")
end
end
Try taking it out of the parentheses. I mean the double parentheses. Also have you tested to make sure that it’s going through? Print statements and checking the console?
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local remote = ReplicatedStorage:WaitForChild("SendWebhook")
local ui = script.Parent
local Main = ui.AdminPanelMain.Main
local kickReason = Main.KickText
local SelectionHandler = require(game:GetService("StarterGui"):WaitForChild("OptionSelectedHandler"))
local textbox = Main.Username
local userId
local thumbType = Enum.ThumbnailType.AvatarBust
local thumbSize = Enum.ThumbnailSize.Size420x420
local selectedPlayerId = nil
local function onEnterPressed(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.Return then
local playerName = textbox.Text
local success, result = pcall(function()
return game:GetService("Players"):GetUserIdFromNameAsync(playerName)
end)
if success then
local content = game.Players:GetUserThumbnailAsync(result, thumbType, thumbSize)
userId = result
selectedPlayerId = result
Main.UserAvatar.Image = content
print(tonumber(result))
else
Main.nonefound.Text = ("Failed to get user ID for " .. playerName)
Main.nonefound.Visible = true
warn("Failed to get user ID for " .. playerName)
wait(2)
Main.nonefound.Visible = false
Main.nonefound.Text = "Label"
end
end
end
local gameProcessedEventEvent = Instance.new("BindableEvent")
gameProcessedEventEvent.Event:Connect(onEnterPressed)
textbox.FocusLost:Connect(function(inputObject, gameProcessedEvent)
gameProcessedEventEvent:Fire(gameProcessedEvent)
end)
local function onKickButtonClicked()
if selectedPlayerId ~= nil then
local playerToKick = game.Players:GetPlayerByUserId(selectedPlayerId)
if playerToKick then
remote:FireServer((tostring(game.Players.LocalPlayer.Name) .. " kicked " .. tostring(playerToKick)), (kickReason.Text), game.Players.LocalPlayer.Name)
playerToKick:Kick(game.Players.LocalPlayer.Name .. " kicked you because ".. kickReason.Text)
print("Kicked " .. selectedPlayerId)
else
warn("Could not find player to kick.")
end
else
warn("No player selected")
end
end
local function onBanButtonClicked()
if selectedPlayerId ~= nil then
local playerToKick = game.Players:GetPlayerByUserId(selectedPlayerId)
if playerToKick then
playerToKick:Kick("You have been banned by "..game.Players.LocalPlayer.Name.. " for" .. kickReason.Text)
print("Banned " .. selectedPlayerId)
else
warn("Could not find player to kick.")
end
else
warn("No player selected")
end
end
local function onWarnButtonClicked()
if selectedPlayerId ~= nil then
print("Warned " .. selectedPlayerId)
else
warn("No player selected")
end
end
local kickButton = Main.Kick
local banButton = Main.Ban
local warnButton = Main.Warn
kickButton.MouseButton1Click:Connect(onKickButtonClicked)
banButton.MouseButton1Click:Connect(onBanButtonClicked)
warnButton.MouseButton1Click:Connect(onWarnButtonClicked)
do you know that the event isnt being fired? try to print something at the beginning of the part where the server script recieves and see if it works, if not tell me