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

For some reason the kick script I just made won't work. Anyone have solutions? (ANSWERED)

I just made a kick script, and nothing happened in output and it didn't kick me. (I said in the chat /e kick FrostedFlakes67). Here's the code, I hope someone can help.

game:GetService("Players").PlayerAdded:Connect(function(plr)
	if plr.UserId == game.CreatorId then
		plr.Chatted:Connect(function(msg)
			local lowermsg = string.lower(msg)
			local command = "/e kick "
			if string.sub(lowermsg,1,#command) == command then
				local PlayerToKick = string.sub(msg,#command,#lowermsg)
				game:GetService("Players"):FindFirstChild(PlayerToKick):Kick("You have been kicked from the game by the game's owner.")
			end
		end)
	end
end)

11 comments

0

Should I have used pcall?

0

i have no idea what pcall is so ill ignore that but ill looking...

0

maybe try game.Players Instead of getservice, usually works if you change that.

0

Pcall is like function, but instead of function, it does not stop if there is an error.

0

this should be in normal script in workspace by the way it looks like, try what i suggested plz

0

Let me change it to game.Players, but this is in ServerScriptService.

0

Just tried, It didn't work.

0

Um, i think iv done that once? if it doesnt work then put in workspace

0

Doing that.

0

Nope, doesn't work in workspace either.

0

OK im just gonna check this whole thing out closer now

2 answers

You people are so complicated- #function this,creator.id that. all you need is a detect, then variable finding the name. Like this, put it in a normal script in workspace!

--By: ME, COMMANDERCAUBUNSIA!
--Tested and worked

game:GetService("Players").PlayerAdded:Connect(function(plr)
    if plr.UserId == game.CreatorId then
        plr.Chatted:Connect(function(msg)
            if string.sub(msg,1,8) == "/e kick " then
                local PlayerToKick = string.sub(msg,9)--if you dont know btw, just puttin begin makes it from that character all the way to the end
                game.Players:FindFirstChild(PlayerToKick):Kick("You have been kicked from the game by the game's owner.")
            end
        end)
    end
end)

11 comments

0

AHA, the (or at least one of the) problem(s) is the 8 line!

0

hold on, im trying the script in studio...

0

mHM! ok, the problem( or one of them) must be (PlayerToKick), you somehow made a mistake there because output says line 8 is a problem and game:getservice also game.Players (i tried both) seemed to kick Me when i separetly did game.(did getsrvice and .players).CommanderCaubunsia:Kick("test"), so the variable PlayerToKick is messed up somehow, im still lokking at that though

0

OH i thing i might know, if you do /e anything, it doesnt appear in chat, so if .Chatted looks for chats in the box, then it wont activate, nevermind, not that

0

Thanks for the answer, there were 2 problems in the code. The first problem was line 3, it didn't identify me as owner, so I changed it to if plr.Name == "FrostedFlakes67" then, and the second problem was line 13. I still don't know what is wrong.

0

ok ill look, thanks for paying attention to my amazing method of finding problems :D

0

Oof, I added a ton of "print"s. Line 13 is your line 8.

0

Wait, let me take apart a free model and look at the script for that. (lol)

0

lul

0

i gtg right now, ill be on later,maybe not today but later. Good Luck!

0

OMG I FOND IT. THE ANSWER, ill tell u later i gtg omg

After looking carefully, I figured out that there was a space before the player's name, so it was trying to kick " FrostedFlakes67". I just fixed it by doing #command+1, and it is now working, but I changed up the script a lot, and put it as a free model. Here is the model: https://web.roblox.com/catalog/03255077426/redirect Here is the new script:

--People using this script: Do not edit this unless you know what you are doing, this will not work if the game is not published, read "README" for instructions.
game:GetService("Players").PlayerAdded:Connect(function(plr)
	print("Player has joined!")
	if plr.UserId == game.CreatorId then
		print("Player is owner!")
		plr.Chatted:Connect(function(msg)
			print("Player has chatted!")
			local lowermsg = string.lower(msg)
			local command = "/e kick "
			if string.sub(lowermsg,-1,#command) == command then
				warn("Owner is kicking someone!")
				local PlayerToKick = string.sub(msg,#command+1,#lowermsg)
				print("Player to kick is: "..PlayerToKick)
				game.Players:FindFirstChild(PlayerToKick):Kick("You have been kicked from the game by the game's owner.")
				warn("Owner kicked "..PlayerToKick.."!")
			end
		end)
	end
end)

Thanks for all the support!

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