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

My ban admin tool won't work it's suppose to loopkick when touched help?

Asked by 5 years ago
local KickMessage = 'Kicked by an admin.'

script.Parent.Handle.Touched:connect(function(hit)
if hit.Parent:FindFirstChild('Humanoid') then
local Player = game:GetService('Players'):GetPlayerFromCharacter(hit.Parent)
while true do wait()
Player:Kick()
          end
     end
end)

Is there anyway to make this work? It's suppose to loop kick the player when hit by the tool.

0
It will error out since when the player is kicked since the player is no longer there. Just store the name of the player and add an if to check if they're there before you kick. climethestair 1663 — 5y
0
Oh no no no, don't store the name of the player, they can change it. Store their ID. davidgingerich 603 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

You gotta use a thread every time you ban someone so like this:

local KickMessage = 'Kicked by an admin.'

script.Parent.Handle.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild('Humanoid') then
    local Player =  game:GetService('Players'):GetPlayerFromCharacter(hit.Parent)
    spawn(function()
        while true do wait()
            if game.Players:FindFirstChild(player) then
                Player:Kick(KickMessage)
            end
        end
    end)
end
end)

So as you see, spawn(function() is a separate thread that lets the while true do run for ever without yielding the script.

If this doesn't work, tell me in the comments, enjoy and if it worked, accept this answer :D

Also, you might ban yourself if you do this so, rip.

0
Awesome! I'll try out if i do ban myself i'll find a way to make it for only some people dont get banned awesomwkidd 11 — 5y
0
ok greatneil80 2647 — 5y
Ad

Answer this question