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

How come my kick command wont work, what's happening?

So I have an admin panel I'm making, and I just finished making the Server Ban(Works fine), but when I finished the Kick command it won't work. What's happening, and can you please help? I know it can't be the button as I have it print right after sending the user's username.

local admins = {
---UserNames
	["vincentthecat1"] = 1;
	["Havok_Ninja"] = 2;
	["EatSomeSand123"] = 3;
---UserId's
	[150334552] = 1;
	[21010010] = 2;
	[896303435] = 3;
	
}

game.Players.PlayerAdded:Connect(function(player)
	if admins[player.Name or player.UserId] then
		local clone = script["Admin Panel"]:Clone()
		clone.Parent = player.PlayerGui
	end
end)
---Server Ban Handler
game.ReplicatedStorage.ServerBanEvent.OnServerEvent:Connect(function(player, victim, reason)
	if admins[player.Name or player.UserId] then
		
		local found = game.Players:FindFirstChild(victim)
		local foundClone = script.victimName:Clone()
		
		if found then
			foundClone.Parent = game.Workspace.ServerBans
			foundClone.Name = found.Name
			foundClone.Value = found.UserId
			found:Kick(reason or "You have been banned.")
		end
		game.Players.PlayerAdded:Connect(function(player)
			if game.Workspace.ServerBans:FindFirstChild(player.Name) then
				player:Kick("You are banned from this server.")
			end
		end)
---Kick Command(not working)
		game.ReplicatedStorage.ServerKickEvent.OnServerEvent:Connect(function(player2, victim2, reason2)
			if admins[player.Name or player.UserId] then ---checks if admin
				
				local foundKick = game.Players:FindFirstChild(victim2)
				
				if foundKick then 
					foundKick:Kick("You have been kicked.") ---kicks(does not work)
				end
			end
		end)
	end
end)

1 answer

✓ Accepted answer

I think the problem is you put the kick player event function inside the ban player event. That means the kick event wont run before you run the ban event.

Studio Output: ( from using command bar with your current script )

game.ReplicatedStorage.ServerKickEvent:FireServer()
-- nothing prints

game.ReplicatedStorage.ServerBanEvent:FireServer()
-- ban event and kick event fired because it wasnt able to run

You should change your code layout:

---Server Ban Handler
game.ReplicatedStorage.ServerBanEvent.OnServerEvent:Connect(function(player, victim, reason)
	if admins[player.Name or player.UserId] then

		local found = game.Players:FindFirstChild(victim)
		local foundClone = script.victimName:Clone()

		if found then
			foundClone.Parent = game.Workspace.ServerBans
			foundClone.Name = found.Name
			foundClone.Value = found.UserId
			found:Kick(reason or "You have been banned.")
		end
		game.Players.PlayerAdded:Connect(function(player)
			if game.Workspace.ServerBans:FindFirstChild(player.Name) then
				player:Kick("You are banned from this server.")
			end
		end)
	end
end)		

---Kick Command
game.ReplicatedStorage.ServerKickEvent.OnServerEvent:Connect(function(player2, victim2, reason2)
	if admins[player2.Name or player2.UserId] then ---checks if admin

		local foundKick = game.Players:FindFirstChild(victim2)

		if foundKick then 
			foundKick:Kick("You have been kicked.") -- kicks player
		end
	end
end)

Studio Output: ( from using command bar with modified script )

game.ReplicatedStorage.ServerKickEvent:FireServer()
-- kick event fired

game.ReplicatedStorage.ServerBanEvent:FireServer()
-- ban event fired

1 comment

0

Thanks for the help!

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