Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
nek_oo 2
6 years ago

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

Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
6 years ago

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)
0
thank you! it worked :)) nek_oo 2 — 6y
Ad

Answer this question