I'm basically implementing a script where it plays an audio object and shuts down the server after a minute if the main object in the game goes missing.
01 | while true do |
02 | if workspace [ "Core" ] then |
03 | print ( "Core Exists" ) |
04 | else |
05 | print ( "ERROR: CORE MISSING" ) |
06 | script.Parent:Play() |
07 | local H = Instance.new( "Hint" ,game.Workspace) |
08 | H.Text = "ERROR: Core Model is Missing or Destroyed. The server will be shut down in about 1 minute." |
09 | wait( 60 ) |
10 | for i,v in pairs (game.Players:GetPlayers()) do |
11 | v:Kick( "Server was shut down due to the Core being missing or destroyed." ) |
12 | end |
13 | break |
14 | end |
15 | wait( 1 ) |
16 | end |
Well I think the problem here is that you're using a loop when you should be using Events instead.
01 | function onChildRemoved(removedInstance) |
02 | if removedInstance.Name = = "Core" then |
03 | for i,v in pairs (Players:GetPlayers()) do |
04 | v:Kick( "Server shutdown!" ) |
05 | end |
06 | else |
07 | print ( "Phew, core is still here :D" ) |
08 | end |
09 | end |
10 |
11 | workspace.ChildRemoved:Connect(onChildRemoved) |
In the code above we have a function that fires every time a child is removed from the workspace. The function checks if the instance that was removed was the Core, and if that's the case we kick everyone. If the core is still there then we will do nothing.