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

How do you delete all "LocalPlayers" without making them crash?

Asked by 9 years ago

I've tried approaching this in many different ways:

game.Players.LocalPlayer:Destroy()

and

game.Players.LocalPlayer.Character:Destroy()

and

game.Players.LocalPlayer.Character.Head:Destroy()

Ps: I'm a beginner scripter who's just learned about "LocalPlayer" and feels like he should know all this, just for future reference.

Update: I decided to make the everything on the player completely transparent, and stopped his controls completely. Thanks for the help, anyway! You're more than welcome to try helping if you want :P

1
With LocalPlayer it is only one player. Also, what do you mean by Delete? EzraNehemiah_TF2 3552 — 9y
0
secretboy6 You do know he means as a Lua script, not by roblox studio. No body except roblox admins has access to the studio ingame on a roblox server. Nickoakz 231 — 9y
0
@Nickoplier Ik that. I was showing him what I'd want the player to be like in the game, Immovable and Invisible.... secretboy6 68 — 9y
0
But this way, it's practically kicking the player, the player can't talk and you cannot bring back the player. If you do this the server ends, you might as well disconnect them. EzraNehemiah_TF2 3552 — 9y

3 answers

Log in to vote
0
Answered by 9 years ago

EDITED

local players=Game.Players
for i,v in ipairs(players:GetChildren()) do
          v.Character.Humanoid.Health=0
end --it appear in Script but not LoclScript,usually
0
Gave the same error as the other script I tried...( Btw, get rid of that period after the "end" :3 " http://gyazo.com/f6bdbd58c3b6aed04609e891d8f07a7f secretboy6 68 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

Do what the other people said to do. Use Kick Instead because you can add a custom message to it.


Kick

Kick disconnects the Client from the Server. You can add a custom message instead of saying, "The game shut down" or something like that. I also like Kick since Kick is usable in Local and Normal scripts.

game:GetService("Player").Player1:Kick()
--Usable in Local and Server script
game:GetService("Player").LocalPlayer:Kick()

Kick("You have been kicked") --You can add a string value/text inside the parentheses for a custom kick message.


Final Product

These are different variations of one script.


Kick when players Join

Normal Script:

game:GetService("Players").PlayerAdded:connect(function(plyr)
    plyr:Kick("You've been kicked") --Edit "You've been kicked" for a custom text.
end)

Local Script

game:GetService("Players").LocalPlayer:Kick("You've been kicked")

Ban script

Normal Script:

banned = {
["Player2"] = true,
["Player3"] = true,
["NAME_OF_PLAYER"] = true
} --You may add more

game:GetService("Players").PlayerAdded:connect(function(plyr)
    if banned[plyr.Name] then
        plyr:Kick("You are banned")
    end
end)

Local Script

banned = {
["Player2"] = true,
["Player3"] = true,
["NAME_OF_PLAYER"] = true
} --You may add more

if banned[game:GetService("Players").LocalPlayer.Name] then
game:GetService("Players").LocalPlayer:Kick("You've been kicked")
end

Kick after 30 seconds

Normal Script:

game:GetService("Players").PlayerAdded:connect(function(plyr)
    wait(30) --Change 30 to different time
    plyr:Kick("You've been kicked")
end)

Local Script

wait(30) --Change to different time
game:GetService("Players").LocalPlayer:Kick("You've been kicked")


Hope it helps!


Extra

In case you're wondering why this was happening, it's because of solo mode, In solo mode the client IS the server. So if you delete the client the server gets deleted too. This won't happen on the actual game though, it only shows up on solo mode.

Log in to vote
-1
Answered by 9 years ago
game.Players.PlayerAdded:connect(function(player)
game.Players.LocalPlayer:Remove()
end
-- I tried Comment on me and tell me if it worked.
0
Players.Player1.PlayerGui.LocalScript:4: ')' expected (to close '(' at line 1) near '<eof>' <~~~~~ Output. secretboy6 68 — 9y
0
Ok.. So what did I get -1 for? Getting it wrong? Why does that matter? It's all about effort... james24dj 90 — 9y
0
^ I wasnt the one to downrate you.... I only have 4 reps secretboy6 68 — 9y
0
I know. It's to the idiot out there who did it. james24dj 90 — 9y

Answer this question