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

For loop and if statements under for loop not workering?

I have a kick command that works upon a player text box input

local replicatestor = game:GetService("ReplicatedStorage")
local kickevent = replicatestor:WaitForChild("KickUser")

local function kickplayer(player, name)
	if kickevent ~= nil then
		for i, v in pairs(game.Players:GetChildren()) do
			if v == name then
				v:Kick("Kicked")
			end
		end
	end
end

kickevent.OnServerEvent:Connect(kickplayer)

the :Kick is not working, any help is appreciated

2 answers

✓ Accepted answer

You are saying if Object == StringValue then (line 7)

You need the player's name, so instead of doing if v == name then do if v.Name == name then

Maybe this could help:

local textBox = script.Parent.Parent:WaitForChild("TextBox")
local textButton = script.Parent
local replicatedEvent = game.ReplicatedStorage:WaitForChild("Kick")
textButton.MouseButton1Down:connect(function()
	local plrs=game.Players:GetPlayers()
	local suspect = nil
	for i=1,#plrs do
		if i[i].Name == textBox.Text then
			suspect=i[i]
		end
	end
	if suspect == nil then
		warn("Player not found")
	else
		suspect:Kick("You have been kicked!")
	end
end)

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