So for a while I’ve been writing an admin panel for general purpose use on my games, and I encountered an issue that is happening when I try to use the “kick” feature in my panel. Here are the scripts:
Local script, inside of a textbox.
local plr = game.Players.LocalPlayer
script.Parent.FocusLost:Connect(function(enterPressed, inputObject)
local players = game.Players:GetChildren()
if enterPressed then
local player = script.Parent.Text
for i,v in pairs(players) do
if v.Name == player then
game.ReplicatedStorage.ccKickEvent:FireServer(plr,player)
print("Player has successfully been found!")
script.Parent.Text = "Player has successfully been found!"
wait(2.5)
script.Parent.Text = "Enter player name to kick!"
end
if v.Name ~= player then
print("Player hasn't been!")
script.Parent.Text = "Player hasn't been found!"
wait(2.5)
script.Parent.Text = "Enter player name to kick!"
end
end
end
end)
script.Parent.Focused:Connect(function()
local name = script.Parent.Text
end)
Server script inside of ServerScriptService
game.ReplicatedStorage.ccKickEvent.OnServerEvent:Connect(function(plr,player)
player:Kick(plr.Name.." has chosen you, "..player.Name.." to be kicked!")
end)
What’s happening is that when I try to kick another person, it just kicks me for no reason. When I try to kick myself, it works perfectly fine.
I tried remove the “plr” in the calling of the remote event, and I got an error:
Any ideas as to why this is happening?
Updated script:
local plr = game.Players.LocalPlayer
script.Parent.FocusLost:Connect(function(enterPressed, inputObject)
local players = game.Players:GetChildren()
if enterPressed then
local player = script.Parent.Text
for i,v in pairs(players) do
if v.Name == player then
game.ReplicatedStorage.ccKickEvent:FireServer(player)
print("Player has successfully been found!")
script.Parent.Text = "Player has successfully been found!"
wait(2.5)
script.Parent.Text = "Enter player name to kick!"
end
if v.Name ~= player then
print("Player hasn't been!")
script.Parent.Text = "Player hasn't been found!"
wait(2.5)
script.Parent.Text = "Enter player name to kick!"
end
end
end
end)
script.Parent.Focused:Connect(function()
local name = script.Parent.Text
end)
game.Players.PlayerAdded:Connect(function(plr)
workspace.ChildAdded:Connect(function(child)
for i,v in pairs(child:GetChildren()) do
if v.Name == "Humanoid" and v:IsA("Humanoid") then
if plr.UserId == 786513213 or plr.UserId == 168464656 then
game.ReplicatedStorage.ccEvent:FireClient(plr)
end
end
end
end)
end)
--if plr.UserId == 786513213 or plr.UserId == 168464656 then
-- game.ReplicatedStorage.ccEvent:FireClient(plr)
--end
game.ReplicatedStorage.ccKickEvent.OnServerEvent:Connect(function(plr,player)
player:Kick(plr.Name.." has chosen you, "..player.Name.." to be kicked!")
end)
game.ReplicatedStorage.ccKillEvent.OnServerEvent:Connect(function(player)
player.Character.Humanoid.Health = 0
end)
game.ReplicatedStorage.ccFreezeEvent.OnServerEvent:Connect(function(plr,player)
player.Character.HumanoidRootPart.Anchored = true
end)
game.ReplicatedStorage.ccHealthEvent.OnServerEvent:Connect(function(plr,hp)
print(hp)
plr.Character.Humanoid.MaxHealth += hp
plr.Character.Humanoid.Health += hp
end)
Most of it is jut reused code from the original kick script, so I was planning on fixing just the kick script so I could re-do the rest of the scripts with my new knowledge.
It works now, but I need to test the script in multiplayer, not just in studio. Thank you.
EDIT: It kind of works, when I insert someone’s name into the text box, it says “Player hasn’t been found!” but then, 2.5 seconds later, it says “Player has been successfully found!” and kicks the person, any ideas as to why this is happening?
EDIT2: Yeah I’m going for the lazy option of doing nothing if the player types in the wrong name lol.