Trying to make a part explode if player is not in a seat

Im trying to make a part that makes an explosion if a player isn’t on a seat

No matter what I do it just doesn’t detect if the player is sitting or not

Tried detecting if the h.seatpart == nil, it only works if the player never entered a seat

function blow(hit)
	local h = hit.Parent:FindFirstChild("Humanoid")
	local Leg = hit.Parent:FindFirstChild("Left Leg")
	if (h.Sit.Value == false) then 
		script.Parent.Sound:play()
		local explosion = Instance.new("Explosion")--Create An Explosion
		explosion.BlastPressure = 1000000
		explosion.BlastRadius = 5 --A 5 by 5 Explosion.
		local Pos = Leg.Position
		explosion.Position = Pos
		explosion.Parent = game.Workspace
	end
end

script.Parent.Touched:connect(blow)

The explosion part works on its own, just not the sit value. The script is just a normal script. The use is to make players stay in their car while they’re in the part. The script is in the part, the seat cant get a script in it

1 Like

Try

function blow(hit)
	local h = hit.Parent:FindFirstChild("Humanoid")
	local Leg = hit.Parent:FindFirstChild("Left Leg")
while wait() do
h.Seated:Connect(Function(bool)
if bool == false then

script.Parent.Sound:play()
		local explosion = Instance.new("Explosion")--Create An Explosion
		explosion.BlastPressure = 1000000
		explosion.BlastRadius = 5 --A 5 by 5 Explosion.
		local Pos = Leg.Position
		explosion.Position = Pos
		explosion.Parent = game.Workspace
break
end)
end
end
end

local connection = script.Parent.Touched:Connect(blow)
2 Likes

You could detect if the seat has an occupant and if it doesn’t it would blow up?

1 Like

i tried it and it didnt work, its showing errors under

end*)*
h.Seated:Connect(*Function*(*bool*)
if *bool* == false then

the stars show the errors

1 Like
function blow(hit)
	local h = hit.Parent:FindFirstChild("Humanoid")
	
	if h then
	
	--local Leg = hit.Parent:FindFirstChild("Left Leg")
	while wait() do
		
		h.Seated:Connect(function(bool)
			if bool == false then

				script.Parent.Sound:play()
				local explosion = Instance.new("Explosion")--Create An Explosion
				explosion.BlastPressure = 1000000
				explosion.BlastRadius = 5 --A 5 by 5 Explosion.
				local Pos = h.Parent.PrimaryPart.Position
				explosion.Position = Pos
				explosion.Parent = game.Workspace
				script:Remove()
			end
		end)
		
		
			
		
		end
		end

end

local connection = script.Parent.Touched:Connect(blow)
2 Likes

Sorry I didn’t test it, I did now It’s fixed I tested it

2 Likes

this is most optimized sorry, this allow for multiple explosions from multiple players, last one would allow only 1 explosion

local seat = script.Parent
local runService = game:GetService("RunService")
local connection
local function whileSeated(Character)
		
		Character.Humanoid.Seated:Connect(function(bool)
				
				if bool==false then
					
					script.Parent.Sound:play()
					local explosion = Instance.new("Explosion")--Create An Explosion
					explosion.BlastPressure = 1000000
					explosion.BlastRadius = 5 --A 5 by 5 Explosion.
					local Pos = Character.PrimaryPart.Position
					explosion.Position = Pos
					explosion.Parent = game.Workspace
					
					
				end
				
	end)
	
	
end

seat.Touched:Connect(function(part)
	
	if part.Parent and part.Parent:FindFirstChild("Humanoid") then
		
		connection = whileSeated(part.Parent)
		
		part.Parent.Humanoid.Died:Connect(function()

			if connection then

				connection:Disconnect()
				connection=nil

			end

		end)

		
	end
	
end)
1 Like

i found 2 problems with this (which could’ve been avoided if I gave more info lol, so basically my fault)
note: I removed the script:Destroy since it needs to be reused
your script did work excellently tho

If players walk in without being in the seat in the first place they don’t explode
If they exit the seat at all (even if they weren’t in the part) they explode

Btw this is just so players cant enter a place without being in a car

1 Like

This is a seat with a script in it.

local Seat, State = script.Parent, false
Seat:GetPropertyChangedSignal("Occupant"):Connect(function() State = not State end)

while wait(3) do 
        if State == true then
		print("sitting")
	end
end
2 Likes

yh this probably the best didn’t know there is singal called “Occupant”