Touching Part Kick Help

so i have a button in my server that admins can press to nuke the server.
but everyone who is in the bunker in time doesnt get kicked from the server.

i tried alot of things to detect if a player is inside a part, but cant get it to work.
can someone help me please, thanks.

this is what i have now:

local click = game.Workspace["High rank Meeting room"]["Self Destruct"]["Self Destruct Initiate"].Button.btn.ClickDetector

function Explode(player)
	click.MaxActivationDistance = 0
	wait(119)
	wait(5)
	warn("Room getting Exlploded")
	local TweenService = game:GetService("TweenService")

	local gui = script.Parent

	local goal = {}
	goal.BackgroundTransparency = 0


	local tweenInfo = TweenInfo.new(
		3, -- Time
		Enum.EasingStyle.Linear, -- EasingStyle
		Enum.EasingDirection.Out, -- EasingDirection
		0, -- RepeatCount (when less than zero the tween will loop indefinitely)
		false, -- Reverses (tween will reverse once reaching it's goal)
		0 -- DelayTime
	)


	local tween = TweenService:Create(gui, tweenInfo, goal)

	tween:Play()
	wait(2)
	local notkicked = {}

	local nokickpart = game.Workspace["Blast Shelter"].NoKickPart

	nokickpart.Touched:Connect(function() end)
	local parts = game.Workspace["Blast Shelter"].NoKickPart:GetTouchingParts()
	for _, part in next, parts do
		if part.Parent:FindFirstChild("Humanoid") then
			if not table.find(notkicked, part.Parent.Name) then 
				table.insert(notkicked, part.Parent.Name)
			end	
		end
	end
	for i,v in pairs(game.Players:GetChildren()) do
		if table.find(notkicked, v.Name) then
			warn(v.Name .. " Survives!")
		elseif not table.find(notkicked, v.Name) then
			v:Kick("???")
		end
	end
	local TweenService2 = game:GetService("TweenService")
	local gui2 = script.Parent
	local goal2 = {}
	goal2.BackgroundTransparency = 0
	
	local tweenInfo2 = TweenInfo.new(
		3, -- Time
		Enum.EasingStyle.Linear, -- EasingStyle
		Enum.EasingDirection.Out, -- EasingDirection
		0, -- RepeatCount (when less than zero the tween will loop indefinitely)
		false, -- Reverses (tween will reverse once reaching it's goal)
		0 -- DelayTime
	)
	
	local tween2 = TweenService2:Create(gui2, tweenInfo2, goal2)
	wait(2)
	tween2:Play()
end


click.MouseClick:Connect(Explode)
1 Like

Hey! There’s so many different ways to do this, but if I was you, I’d just create a table and add everyone who touched an “entrance” part to that table. I’ve written some code for you below, obviously this might not have all the features you would like, but hopefully it’ll help!

local ClickDetector = script.Parent.Button.ClickDetector --Click Detector
local Detector = script.Parent.Entrance --Entrance part mentioned on line 36.


local SafePlayers = {}



function Safe(Hit)
	if table.find(SafePlayers, Hit.Parent.Name) then --Checking if they're already in the bunker
		return --Returning if they're already in the bunker
	else
		table.insert(SafePlayers, Hit.Parent.Name) --Inserting their username into the "SafePlayers" table.
	end
end



function Explode(Player)
	wait(5) --This is the amount of time people have to get to the bunker.
	for _, v in pairs (game.Players:GetChildren()) do --Looping through the Players
		if table.find(SafePlayers, v.Name) then --Checking if each player is in the bunker.
			return --Returning if they are in the bunker.
		else
			v:Kick("You died!") --Kicking the player if they are not in the bunker.
		end
	end
end


Detector.Touched:Connect(Safe) --Firing the "Safe" function when someone touches the entrance part of the bunker. For this I put an invisible part infront of the entrance and turned the collissions off.
ClickDetector.MouseClick:Connect(Explode) --Firing the "Explode" function when someone clicks the button. 

Hope this helped!

2 Likes

thx this works, but when a player leaves the bunker before the explosion then they are still in SafePlayers table. i tried to fix this using:


	function UnSafe(Hit)
		if Hit.Parent:FindFirstChild("Humanoid") then
			if table.find(SafePlayers, Hit.Parent.Name) then
				table.remove(SafePlayers, Hit.Parent.Name)
			else
				return
			end
		else
			warn("Not a player")
		end
	end
Detector.Touched:Connect(UnSafe)

but then i touch it i get added and quickly removed from the table.
can you help me with this problem?