I added the seat script on the bottom and it worked. I had then tested it and the damage was broken. I had then added a timer to the seat and both are broken.
local TableOfHit = {}
local Hitbox = script.Parent:WaitForChild("Hitbox")
Hitbox.Touched:Connect(function(Object)
if table.find(TableOfHit, Object.Parent) then return end -- If the character is in table, then return.
-- Find humanoid, if not found then return.
local Humanoid = Object.Parent:FindFirstChildWhichIsA("Humanoid")
if not Humanoid then return end
-- Insert the character and then save its position. We take 5 damage here.
table.insert(Object.Parent)
local Pos = #TableOfHit
Humanoid:TakeDamage(5)
-- After we take damage, we use the "task" library to multithread, as to not yield the script. Delay just waits for a certain amount of time to call a function.
task.delay(5, function()
local Seat: Seat = script.Parent:FindFirstChild("Seat")
-- If Seat does not exist or occupants then return end.
if not Seat then return end
if Seat.Occupant then return end
-- Sit the humanoid to the seat.
Seat:Sit(Humanoid)
task.wait(5)
-- After 5 seconds, we remove the character from the table.
table.remove(TableOfHit, Pos)
end)
end)
--Add a 5 second delay to the seat.
task.wait(5)
table.remove(TableOfHit, Pos)
script.Parent.Touched:connect(function(obj)
if obj.Parent:FindFirstChild("Humanoid") then
obj.Parent.Humanoid.Sit = true
end
end)