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

Kicking script is giving me errors and not kicking the player?

Asked by
Rinextel 291 Moderation Voter
5 years ago
Edited 5 years ago
function OnPlayerEntered(plr) 
    local pName = plr.Name
    if pName == "19under19" then
    --Kicking code
plr:kick("You are banned from this game!")

    end
end

game.Players.PlayerAdded:connect (OnPlayerEntered)

This is the script I have in a server script in workspace. It is not kicking the player is it supposed to. Help?

2 answers

Log in to vote
1
Answered by 5 years ago
function OnPlayerEntered(plr)
    local pName = plr.Name
    if pName == "19under19" then
        wait(1)
        plr:Kick("You are banned from this game!")
    end
end

game.Players.PlayerAdded:Connect(OnPlayerEntered)

I made 3 changes;

1. I added a wait(1) before kicking the player, Roblox has some things to do when a player joins, and if the player is removed before it's ready then it can cause some errors

2. I changed "connect" to "Connect" on the last line, "connect" is deprecated.

3. I changed "plr:kick" to "plr:Kick", I'm not 100% sure if it's deprecated but on the Roblox Wiki it's capitalized so why not

0
Thanks. I forgot that Kick is deprecated. Rinextel 291 — 5y
Ad
Log in to vote
-2
Answered by 5 years ago

When answering, if your answer does not fully solve the question, it should be written as a comment to the question instead of as an answer.

Please rate my comment correct.

    function OnPlayerEntered(plr)
        local pName = plr.Name
        if pName == "19under19" then
        --[Kicking code]--
    plr:kick("You are banned from this game!")

        end
    end

    game.Players.PlayerAdded:connect (OnPlayerEntered)
0
you didn't even change anything.. User#1007 6 — 5y

Answer this question