Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

What is the trigger to detect when a player sits in a seat?

What I want to do is have an explosion trigger 5 seconds after someone sits in a seat. The only thing I need help with is what trigger or function to use. This is the explosion.

local explosionPart = script.Parent
local explosion = Instance.new("Explosion", game.Workspace)
explosion.Position = explosionPart.Position
explosionPart:Destroy()

The script is inside of the part I want to explode (a computer screen)

1 answer

✓ Accepted answer
local explosionPart = script.Parent
local explosion = Instance.new("Explosion")
script.Parent.Touched:Connect(function(hit) -- Detects a player
if hit.Parent:FindFirstChild("Humanoid") ~= nil then
	local Hum = hit.Parent:WaitForChild("Humanoid")
	if Hum.Sit == true then
	explosion.Parent = explosionPart
	explosionPart:Destroy()
	end
end
end)

-- Hope I helped

or if upper ones don't work try this one, most likely that the second code will work:

local explosionPart = script.Parent
local explosion = Instance.new("Explosion")

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
	local Hum = character:WaitForChild("Humanoid")
		Hum.Seated:Connnect(function(isSeated, seat)
			if seat == explosionPart and isSeated then
			explosion.Parent = explosionPart
			explosionPart:Destroy()
			end
		end)
	end)
end)

-- Hope I helped*2

2 comments

0

seat.Occupant, not humanoid.Seated

0

Also, stop spoonfeeding code. Spoonfeeding does not help the asker know what their problem is and how they should solve it.

This discussion is preserved as it was. New answers, comments, and votes are closed.