Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My admin panel's kick command is not working. What did I do wrong?

I was making a kick command for my admin panel and it didn't work. I did not even get an error.

The local script:

local kickEvent = game.ReplicatedStorage.Commands.Kick -- this is for the kick
local target = script.Parent.Player -- this is the target
local reason = script.Parent.Reason -- the reason for a kick, and, ban
local player = game.Players.LocalPlayer -- this is the player on the admin panel
local panel = script.Parent --This is for the admin panel

panel.Kick.MouseButton1Click:Connect(function()
	kickEvent:FireServer(player, target, reason)
end)

This is the event script:

local commands = game.ReplicatedStorage.Commands
local playerService = game.Players

commands.Kick.OnServerEvent:Connect(function(player, reason, target)
	playerService.target.Text:Kick(reason.Text)
end)

commands.GlobalBan.OnServerEvent:Connect(function()
	
end)

commands.ServerBan.OnServerEvent:Connect(function()
	
end)

commands.GiveModItem.OnServerEvent:Connect(function()
	
end)

2 answers

In the event script, you tried to find an instance called 'target' in players.

Instead of doing that, you can use FindFirstChild, that way you can find the target.

commands.Kick.OnServerEvent:Connect(function(player, reason, target)
    playerService:FindFirstChild(target).Text:Kick(reason.Text)
end)

2 comments

0

your code is wrong plus this is not efficient, you dont need to sent the instance as an argument, you can just send the text

0

also, im pretty sure the text is local so you cant access it from the server

you dont need to send in the instance, you can just send the text of the text objects. so your local script might look like this:

local kickEvent = game.ReplicatedStorage.Commands.Kick -- this is for the kick
local target = script.Parent.Player.Text -- this is the target
local reason = script.Parent.Reason.Text -- the reason for a kick, and, ban
--local player = game.Players.LocalPlayer -- this is the player on the admin panel
local panel = script.Parent --This is for the admin panel

panel.Kick.MouseButton1Click:Connect(function()
    kickEvent:FireServer(target, reason)
end)

And your server script might look like this:

local commands = game.ReplicatedStorage.Commands
local playerService = game.Players

commands.Kick.OnServerEvent:Connect(function(player, target, reason)
 
local player_to_kick = playerService:FindFirstChild(target)


if player_to_kick then
player_to_kick:Kick(reason)

end

end)

commands.GlobalBan.OnServerEvent:Connect(function()

end)

commands.ServerBan.OnServerEvent:Connect(function()

end)

commands.GiveModItem.OnServerEvent:Connect(function()

end)

Hope I helped!

This discussion is preserved as it was. New answers, comments, and votes are closed.