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)
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)
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!