Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
Edited 5 years ago

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

Log in to vote
2
Answered by 5 years ago
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
0
seat.Occupant, not humanoid.Seated DeceptiveCaster 3761 — 5y
0
Also, stop spoonfeeding code. Spoonfeeding does not help the asker know what their problem is and how they should solve it. DeceptiveCaster 3761 — 5y
Ad

Answer this question