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
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
Do what the other people said to do. Use Kick Instead because you can add a custom message to it.
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.
These are different variations of one script.
game:GetService("Players").PlayerAdded:connect(function(plyr) plyr:Kick("You've been kicked") --Edit "You've been kicked" for a custom text. end)
game:GetService("Players").LocalPlayer:Kick("You've been kicked")
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)
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
game:GetService("Players").PlayerAdded:connect(function(plyr) wait(30) --Change 30 to different time plyr:Kick("You've been kicked") end)
wait(30) --Change to different time game:GetService("Players").LocalPlayer:Kick("You've been kicked")
Hope it helps!
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.
game.Players.PlayerAdded:connect(function(player) game.Players.LocalPlayer:Remove() end -- I tried Comment on me and tell me if it worked.