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

Kick button/script does not show error in the log, but does not work when i click the button?

I am a real noob at scripting I tried to run this script and it kicks the user if they are not allowed (which is what its supposed to do) but it doesn't kick the user whose name I put in.

repeat wait() until game.Players.LocalPlayer
local plr = game.Players.LocalPlayer
local name = script.Parent.Parent:WaitForChild("Name").Text
local unfilteredreason = script.Parent.Parent:WaitForChild("Reason").Text
local mod = script.Parent.Parent:WaitForChild("Mod").Text
script.Parent.MouseButton1Click:connect(function()
	 if plr:GetRankInGroup(2823155) == 255 or plr:GetRankInGroup(2823155) > 251 or plr.Name == "Player1" then
		for _,v in pairs(game.Players:GetChildren()) do
			if v.Name == name then
				local reason = game:GetService("Chat"):FilterStringForBroadcast(unfilteredreason,plr)
				v:Kick(reason)
			end
		end
	else
		plr:Kick("Why are you here??")
	end
end)

it gives me no error in the log also i dont know why "game:GetService("Chat"):FilterStringForBroadcast(unfilteredreason,plr)" is not formatting correctly it is correct in the script

1 answer

✓ Accepted answer

Explained in the comments because I have to go, good luck!

repeat wait() until game.Players.LocalPlayer
local plr = game.Players.LocalPlayer
-- Grabbing the Text here will only index it once, not when you change it. 
local name = script.Parent.Parent:WaitForChild("Name")
local unfilteredreason = script.Parent.Parent:WaitForChild("Reason")
local mod = script.Parent.Parent:WaitForChild("Mod").Text
script.Parent.MouseButton1Click:connect(function()
     if plr:GetRankInGroup(2823155) == 255 or plr:GetRankInGroup(2823155) > 251 or plr.Name == "Player1" then
        for _,v in pairs(game.Players:GetChildren()) do
            if v.Name == name.Text then
				-- You're supposed to be kicking the player you found in the loop
				-- that matches your textbox, not the LocalPlayer (That's the player running this!")
                local reason = game:GetService("Chat"):FilterStringForBroadcast(unfilteredreason.Text, v)
                v:Kick(reason)
            end
        end
    else
       plr:Kick("Why are you here??")
    end
end)

1 comment

0

thank you! it worked :))

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