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

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

Asked by 4 years ago
Edited 4 years ago

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)
0
Should I have used pcall? FrostedFlakes67 71 — 4y
0
i have no idea what pcall is so ill ignore that but ill looking... CommanderCaubunsia 126 — 4y
0
maybe try game.Players Instead of getservice, usually works if you change that. CommanderCaubunsia 126 — 4y
0
Pcall is like function, but instead of function, it does not stop if there is an error. FrostedFlakes67 71 — 4y
View all comments (7 more)
0
this should be in normal script in workspace by the way it looks like, try what i suggested plz CommanderCaubunsia 126 — 4y
0
Let me change it to game.Players, but this is in ServerScriptService. FrostedFlakes67 71 — 4y
0
Just tried, It didn't work. FrostedFlakes67 71 — 4y
0
Um, i think iv done that once? if it doesnt work then put in workspace CommanderCaubunsia 126 — 4y
0
Doing that. FrostedFlakes67 71 — 4y
0
Nope, doesn't work in workspace either. FrostedFlakes67 71 — 4y
0
OK im just gonna check this whole thing out closer now CommanderCaubunsia 126 — 4y

2 answers

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

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)
0
AHA, the (or at least one of the) problem(s) is the 8 line! CommanderCaubunsia 126 — 4y
0
hold on, im trying the script in studio... CommanderCaubunsia 126 — 4y
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 CommanderCaubunsia 126 — 4y
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 CommanderCaubunsia 126 — 4y
View all comments (7 more)
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. FrostedFlakes67 71 — 4y
0
ok ill look, thanks for paying attention to my amazing method of finding problems :D CommanderCaubunsia 126 — 4y
0
Oof, I added a ton of "print"s. Line 13 is your line 8. FrostedFlakes67 71 — 4y
0
Wait, let me take apart a free model and look at the script for that. (lol) FrostedFlakes67 71 — 4y
0
lul CommanderCaubunsia 126 — 4y
0
i gtg right now, ill be on later,maybe not today but later. Good Luck! CommanderCaubunsia 126 — 4y
0
OMG I FOND IT. THE ANSWER, ill tell u later i gtg omg CommanderCaubunsia 126 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

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!

Answer this question